Objective-C中的Google用户serverAuthCode为零

时间:2016-03-01 17:44:14

标签: ios objective-c google-signin

我尝试将GoogleSignIn框架集成到iOS应用中,并对服务器上的用户进行身份验证。我设法登录用户,但在- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error委托方法中,user.serverAuthCodenil,我需要将此服务器身份验证代码传递给服务器上的用户身份验证代码

我看了this documentation page并说明我必须设置serverClientID的{​​{1}}属性,但无处是否说明我在哪里找到这个"服务器客户端ID"。我用世界上所有的钥匙进行测试都无济于事。

然后我发现this documentation page看起来好像在试图告诉我们在哪里可以找到这个神奇的内容,但它使用了不好的措辞并没有帮助。我确实拥有类型为[GIDSignIn sharedInstance]的OAuth2凭据,但是:

  1. 它们用于网络(客户端)应用程序,对应于我的iOS应用程序,它也与服务器通信
  2. 我尝试过使用它,但它没有用。
  3. 有没有人设法成功逃脱Google (可怜)文档的手中?

6 个答案:

答案 0 :(得分:7)

您需要确保设置[GIDSignIn sharedInstance].serverClientID属性;该值可在Google API控制台中找到。

此外,如果您的user.serverAuthCode值为nil,请确保在后续尝试之前调用[[GIDSignIn sharedInstance] signOut];。否则[GIDSignIn sharedInstance]似乎记得先前的配置。

我在模拟器中获取serverAuthCode没有问题。

答案 1 :(得分:5)

在模拟器中尝试 NOT 运行它:)

答案 2 :(得分:2)

有同样的问题。 GIDSignIn.sharedInstance().serverClientIDGIDSignIn.sharedInstance().clientID相同。 通过设置serverClientId来解决。

答案 3 :(得分:1)

你可以在plist中找到client_id,和 您可以通过API控制台管理器找到server_client_id。

你必须先删除应用程序,然后再尝试再做,模拟器或设备,它会起作用。

答案 4 :(得分:1)

使用此配置获取不是serverAuthCode的{​​{1}}:

nil

其中:

  • NSError *configureError; [[GGLContext sharedInstance] configureWithError:&configureError]; NSAssert(!configureError, @"Error configuring Google services: %@", configureError); [GIDSignIn sharedInstance].clientID = @"88.....apps.googleusercontent.com"; [GIDSignIn sharedInstance].serverClientID = @"88.....apps.googleusercontent.com" ; [GIDSignIn sharedInstance].shouldFetchBasicProfile = YES; [GIDSignIn sharedInstance].scopes = @[@"email", @"profile"]; 使用clientID中的REVERSED_CLIENT_ID值。
  • GoogleService-Info.plist使用serverClientID
  • 中的相应值

答案 5 :(得分:0)

user获取访问令牌:

NNString* accessToken = user.authentication.accessToken;