iOS上的GTM OAuth 2.0-检索用户';s电子邮件

iOS上的GTM OAuth 2.0-检索用户';s电子邮件,ios,oauth,oauth-2.0,gtm-oauth2,google-oauth,Ios,Oauth,Oauth 2.0,Gtm Oauth2,Google Oauth,GTMOauth2.0似乎是在iOS上进行OAuth2.0验证的极好工具。我试图通过在Xcode中实现GTMOAuth-2来检索Google用户的全名和电子邮件,但遇到了一些麻烦。基于这个答案:,它应该像调用auth.userEmail一样简单。但是,问题是在以下代码段中调用auth.userEmail总是返回null: - (void)viewController:(GTMOAuth2ViewControllerTouch * )viewController finishedWithAut

GTMOauth2.0似乎是在iOS上进行OAuth2.0验证的极好工具。我试图通过在Xcode中实现GTMOAuth-2来检索Google用户的全名和电子邮件,但遇到了一些麻烦。基于这个答案:,它应该像调用
auth.userEmail
一样简单。但是,问题是在以下代码段中调用
auth.userEmail
总是返回
null

- (void)viewController:(GTMOAuth2ViewControllerTouch * )viewController
  finishedWithAuth:(GTMOAuth2Authentication * )auth
             error:(NSError * )error
{
NSLog(@"finished");
NSLog(@"auth access token: %@", auth.accessToken);

[self.navigationController popToViewController:self animated:NO];
if (error != nil) {
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error Authorizing with Google"
                                                     message:[error localizedDescription]
                                                    delegate:nil
                                           cancelButtonTitle:@"OK"
                                           otherButtonTitles:nil];
    [alert show];
} else {

    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Success Authorizing with Google"
                                                     message:[error localizedDescription]
                                                    delegate:nil
                                           cancelButtonTitle:@"OK"
                                           otherButtonTitles:nil];
    [alert show];
}
NSLog(@"email: %@",auth.userEmail);
}

代码成功运行并检索访问令牌,但
auth.userEmail
始终为
null
。我是否需要使用GTMOAuth 2.0的
Fetcher
对象向Google电子邮件端点发出请求,或者使用
auth.accessToken
发送额外的HTTP GET请求来检索用户的电子邮件

我最近在
googleoauth2
上工作,用
gmail
通过遵循tutsplus的教程,它给了我想要的结果 建议您点击此链接。这提供了
登录
注销
以及登录用户的电子邮件地址。 . 若要获取登录用户的电子邮件地址,请将其添加到范围中
https://www.googleapis.com/auth/userinfo.email
。代码将显示 像这样

对于GTM OAuth 2.0,添加以下内容 范围<代码>https://www.googleapis.com/auth/userinfo.email。希望这有帮助 你

 [_googleOAuth authorizeUserWithClienID:@"YOUR CLIENT ID"
                           andClientSecret:@"SECRET"
                             andParentView:self.view
                                 andScopes:[NSArray arrayWithObjects:@"https://www.googleapis.com/auth/userinfo.profile",@"https://www.googleapis.com/auth/userinfo.email", nil]];