在iOS中,使用google + sdk并专门关注他们的sign-in documentation
我似乎得到一个零用户ID,例如[[GPPSignIn sharedInstance] userID]
为nil
我第一次授权应用程序时,我获得了一个有效的userId,但是第二次进入我的应用程序期望看到有效的用户ID,它再次为零。
当我检查[[GPPSignIn sharedInstance] trySilentAuthentication]
时,它返回true。
我正在遵循与sample project中描述的非常相似的情况。 可能导致这种情况的原因是什么?
答案 0 :(得分:0)
我做了以下几个步骤来解决这个问题:
将这些属性设置为true
googleSignin.scopes = ["https://www.googleapis.com/auth/plus.me", "https://www.googleapis.com/auth/plus.login", "https://www.googleapis.com/auth/calendar", "https://www.googleapis.com/auth/userinfo.profile"]
googleSignin.shouldFetchGoogleUserID = true
googleSignin.shouldFetchGoogleUserEmail = true
googleSignin.shouldFetchGooglePlusUser = true
在GPPSignIn.sharedInstance().userID
auth.userID
而不是finishedWithAuth(auth: error:)
醇>
答案 1 :(得分:0)
Google用户ID。它仅在| shouldFetchGoogleUserID |时可用设置并尝试| trySilentAuthentication |或者|验证|已经成功完成。你可以使用它。
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES;
signIn.shouldFetchGoogleUserID = YES;
signIn.delegate = self;
signIn.clientID = kClientId;
signIn.scopes = @[kGTLAuthScopePlusLogin];
signIn.actions = [NSArray arrayWithObjects:@"http://schemas.google.com/ListenActivity",nil];
[signIn authenticate];