GPPSignIn sharedInstance userID始终为nil

时间:2013-08-26 14:06:09

标签: ios google-plus

在iOS中,使用google + sdk并专门关注他们的sign-in documentation 我似乎得到一个零用户ID,例如[[GPPSignIn sharedInstance] userID]nil

我第一次授权应用程序时,我获得了一个有效的userId,但是第二次进入我的应用程序期望看到有效的用户ID,它再次为零。 当我检查[[GPPSignIn sharedInstance] trySilentAuthentication]时,它返回true。

我正在遵循与sample project中描述的非常相似的情况。 可能导致这种情况的原因是什么?

2 个答案:

答案 0 :(得分:0)

我做了以下几个步骤来解决这个问题:

  1. 在Google Developer Console中启用Google+ API
  2. 将这些属性设置为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
    
  3. GPPSignIn.sharedInstance().userID

  4. 中使用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];