您必须在谷歌集成中指定clientID异常

时间:2021-03-15 15:23:41

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 uncaught exception 'NSInvalidArgumentException', reason: 'You must specify |clientID| for |GIDSignIn|

由于未捕获异常“NSInvalidArgumentException”,原因是:“必须为|GIDSignIn|指定|clientID|

I double checked my code.Even i set client-id getting this exception.Where i went wrong?any help will be appreciated.thanks in advance

我仔细检查了我的代码。即使我设置了客户端id也会得到这个异常。我哪里出错了吗?如有任何帮助,我们将不胜感激。谢谢提前

6 个解决方案

#1


13  

I was following Google's own guide for adding Sign-In here. I followed it step by step - integrated the google configuration file too. As per the guide, if the configuration file was included, setting the client id manually was not required. Unfortunately, I encountered exactly the same error when I run the app and hit the Sign-In button:

我遵循谷歌自己的指南在这里添加登录。我一步一步地跟踪它,也集成了谷歌配置文件。根据指南,如果包含配置文件,则不需要手动设置客户端id。不幸的是,当我运行应用程序并点击登录按钮时,我遇到了完全相同的错误:

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

由于未被发现的异常“NSInvalidArgumentException”而终止应用程序,原因是:“必须为|GIDSignIn|指定|clientID|”

Solution:

解决方案:

For some reason, clientID was not automatically picked from the configuration file. We should instead configure the GIDSignIn object directly, (using the client ID found in the GoogleService-Info.plist file) in the app delegate's application:didFinishLaunchingWithOptions: method:

由于某些原因,clientID没有从配置文件中自动选择。相反,我们应该直接配置GIDSignIn对象(使用GoogleService-Info中找到的客户端ID)。在app委托的应用程序中: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
}

Also, if you are using Firebase, you can do it this way too:

另外,如果你正在使用Firebase,你也可以这样做:

GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID

#2


3  

It looks like the auto-generated config file, GoogleService-Info.plist, will include the wrong credentials by default; it includes the Web Client credentials instead of the iOS app credentials.

它看起来像一个自动生成的配置文件,GoogleService-Info。plist,默认将包含错误的凭证;它包括Web客户端凭据,而不是iOS应用程序凭据。

You need to correct the Client ID and the Reverse Client ID in the GoogleService-Info.plist.

您需要更正GoogleService-Info.plist中的客户端ID和反向客户端ID。

Since these credentials are also used in your app's URLSchemes, you need to correct this there too.

由于这些凭证在应用程序的urlscheme中也使用,所以您也需要在这里进行更正。

#3


0  

The clientId definitely does get picked up from the .plist file. If it appears not to be, it is likely that your code is attempting to use the sign-in object before it has been properly configured. Set a breakpoint on your configureWithError line, and make sure that it gets hit before any attempt to set a delegate, perform silent sign-in, etc.

clientId肯定是从.plist文件中获取的。如果看起来不是,很可能您的代码在正确配置登录对象之前正在尝试使用它。在configure rewitherror行上设置一个断点,并确保它在设置委托之前被命中,执行静默登录等等。

#4


0  

Looks like the sign in method has now been updated by google, I was implementing the Google Calendar for iOS app and I found the following code for Sign In:

看来登录方法已经被谷歌更新了,我正在为iOS app实现谷歌日历,发现登录代码如下:

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 which gave the same error:

在他们的文件中也有同样的错误:

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

I took the lines which were inside:

我画了里面的线条

func applicationDidFinishLaunching(_ application: UIApplication)

and put them in this method and sign in worked:

并将其放入该方法中,并在工作中签字:

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

Code for refernce:

代码选择依据:

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
}

#5


0  

You may need to obtain GoogleService-Info.plist from https://console.firebase.google.com rather than https://console.developers.google.com/.

您可能需要获取googleservice信息。plist来自https://console.firebase.google.com而不是https://console.developers.google.com/。

#6


0  

Using Firebase remember also that you have to call Firebase.configure() function before you set the clientId. Otherwise, it won't work.

使用Firebase还要记住,在设置clientId之前必须调用Firebase.configure()函数。否则,它不能工作。

#1


13  

I was following Google's own guide for adding Sign-In here. I followed it step by step - integrated the google configuration file too. As per the guide, if the configuration file was included, setting the client id manually was not required. Unfortunately, I encountered exactly the same error when I run the app and hit the Sign-In button:

我遵循谷歌自己的指南在这里添加登录。我一步一步地跟踪它,也集成了谷歌配置文件。根据指南,如果包含配置文件,则不需要手动设置客户端id。不幸的是,当我运行应用程序并点击登录按钮时,我遇到了完全相同的错误:

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

由于未被发现的异常“NSInvalidArgumentException”而终止应用程序,原因是:“必须为|GIDSignIn|指定|clientID|”

Solution:

解决方案:

For some reason, clientID was not automatically picked from the configuration file. We should instead configure the GIDSignIn object directly, (using the client ID found in the GoogleService-Info.plist file) in the app delegate's application:didFinishLaunchingWithOptions: method:

由于某些原因,clientID没有从配置文件中自动选择。相反,我们应该直接配置GIDSignIn对象(使用GoogleService-Info中找到的客户端ID)。在app委托的应用程序中: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
}

Also, if you are using Firebase, you can do it this way too:

另外,如果你正在使用Firebase,你也可以这样做:

GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID

#2


3  

It looks like the auto-generated config file, GoogleService-Info.plist, will include the wrong credentials by default; it includes the Web Client credentials instead of the iOS app credentials.

它看起来像一个自动生成的配置文件,GoogleService-Info。plist,默认将包含错误的凭证;它包括Web客户端凭据,而不是iOS应用程序凭据。

You need to correct the Client ID and the Reverse Client ID in the GoogleService-Info.plist.

您需要更正GoogleService-Info.plist中的客户端ID和反向客户端ID。

Since these credentials are also used in your app's URLSchemes, you need to correct this there too.

由于这些凭证在应用程序的urlscheme中也使用,所以您也需要在这里进行更正。

#3


0  

The clientId definitely does get picked up from the .plist file. If it appears not to be, it is likely that your code is attempting to use the sign-in object before it has been properly configured. Set a breakpoint on your configureWithError line, and make sure that it gets hit before any attempt to set a delegate, perform silent sign-in, etc.

clientId肯定是从.plist文件中获取的。如果看起来不是,很可能您的代码在正确配置登录对象之前正在尝试使用它。在configure rewitherror行上设置一个断点,并确保它在设置委托之前被命中,执行静默登录等等。

#4


0  

Looks like the sign in method has now been updated by google, I was implementing the Google Calendar for iOS app and I found the following code for Sign In:

看来登录方法已经被谷歌更新了,我正在为iOS app实现谷歌日历,发现登录代码如下:

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 which gave the same error:

在他们的文件中也有同样的错误:

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

I took the lines which were inside:

我画了里面的线条

func applicationDidFinishLaunching(_ application: UIApplication)

and put them in this method and sign in worked:

并将其放入该方法中,并在工作中签字:

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

Code for refernce:

代码选择依据:

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
}

#5


0  

You may need to obtain GoogleService-Info.plist from https://console.firebase.google.com rather than https://console.developers.google.com/.

您可能需要获取googleservice信息。plist来自https://console.firebase.google.com而不是https://console.developers.google.com/。

#6


0  

Using Firebase remember also that you have to call Firebase.configure() function before you set the clientId. Otherwise, it won't work.

使用Firebase还要记住,在设置clientId之前必须调用Firebase.configure()函数。否则,它不能工作。