我尝试将GoogleSignIn
框架集成到iOS应用中,并对服务器上的用户进行身份验证。我设法登录用户,但在- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error
委托方法中,user.serverAuthCode
是nil
,我需要将此服务器身份验证代码传递给服务器上的用户身份验证代码
我看了this documentation page并说明我必须设置serverClientID
的{{1}}属性,但无处是否说明我在哪里找到这个"服务器客户端ID"。我用世界上所有的钥匙进行测试都无济于事。
然后我发现this documentation page看起来好像在试图告诉我们在哪里可以找到这个神奇的内容,但它使用了不好的措辞并没有帮助。我确实拥有类型为[GIDSignIn sharedInstance]
的OAuth2凭据,但是:
有没有人设法成功逃脱Google (可怜)文档的手中?
答案 0 :(得分:7)
您需要确保设置[GIDSignIn sharedInstance].serverClientID
属性;该值可在Google API控制台中找到。
此外,如果您的user.serverAuthCode
值为nil
,请确保在后续尝试之前调用[[GIDSignIn sharedInstance] signOut];
。否则[GIDSignIn sharedInstance]
似乎记得先前的配置。
我在模拟器中获取serverAuthCode
没有问题。
答案 1 :(得分:5)
在模拟器中尝试 NOT 运行它:)
答案 2 :(得分:2)
有同样的问题。 GIDSignIn.sharedInstance().serverClientID
与GIDSignIn.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;