IOS swift Must specify ClientID exception in google integration

code:

let signIn = GPPSignIn.sharedInstance() signIn.shouldFetchGooglePlusUser = true signIn.clientID = "912597493260-qg351fl8olmnmjl8qobos8n6u909jp0o.apps.googleusercontent.com" signIn.scopes = [kGTLAuthScopePlusLogin]; signIn.trySilentAuthentication(); GIDSignIn.sharedInstance().signInSilently() signIn.delegate = self 

due to the undetected exception "NSInvalidArgumentException", reason: "You must specify | clientID | for | GIDSignIn |

I double checked my code. Even I set the client id, getting this exception. Where am I wrong? Any help would be appreciated. thanks in advance

+5
source share
6 answers

I followed Google’s own guide for adding Sign-In here . I followed it step by step - also integrated the google configuration file. According to the manual, if a configuration file was included, manual installation of the client ID is not required. Unfortunately, I encountered the same error when starting the application and pressed the login button:

The application terminated due to the uncaught exception "NSInvalidArgumentException", reason: "You must specify | clientID | for | GIDSignIn | '

Decision:

For some reason, the client identifier was not automatically selected from the configuration file. Instead, we must directly configure the GIDSignIn object (using the client ID found in the GoogleService-Info.plist file) in the delegate method application:didFinishLaunchingWithOptions: ::

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Initialize sign-in var configureError: NSError? GGLContext.sharedInstance().configureWithError(&configureError) assert(configureError == nil, "Error configuring Google services: \(configureError)") GIDSignIn.sharedInstance().clientID = "Cliend id From GoogleService-Info.plist file" GIDSignIn.sharedInstance().delegate = self return true } 

Alternatively, if you use Firebase, you can also do this:

 GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID 
+13
source

It appears that the automatically generated configuration file, GoogleService-Info.plist, will include invalid default credentials; it includes web client credentials instead of iOS app credentials.

You need to fix the client ID and return client ID in GoogleService-Info.plist.

Since these credentials are also used in the URLs of your application, you also need to fix this.

+3
source

ClientId definitely comes from a .plist file. If this is not the case, your code is probably trying to use the login object before it is properly configured. Set a breakpoint on your configureWithError line and make sure that it hits before trying to set a delegate, silently log in, etc.

0
source

It looks like the sign method has now been updated by google, I used the Google Calendar app for iOS and I found the following login code:

 func applicationDidFinishLaunching(_ application: UIApplication) { // Initialize sign-in var configureError: NSError? GGLContext.sharedInstance().configureWithError(&configureError) assert(configureError == nil, "Error configuring Google services: \(configureError!)") } 

in their document that gave the same error:

 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'You must specify |clientID| for |GIDSignIn|' 

I took the lines that were inside:

 func applicationDidFinishLaunching(_ application: UIApplication) 

and put them in this method and log in:

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool 

Code for reference:

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. // Initialize sign-in var configureError: NSError? GGLContext.sharedInstance().configureWithError(&configureError) assert(configureError == nil, "Error configuring Google services: \(configureError!)") return true } 
0
source

You may need to get GoogleService-Info.plist from https://console.firebase.google.com , not https://console.developers.google.com/ .

0
source

Using Firebase also remembers that before setting clientId you must call the Firebase.configure () function. Otherwise it will not work.

0
source

All Articles