我已经整合了谷歌加在我的IOS应用程序,但我无法获得当前login的用户的电子邮件ID

我已经在我的iOS应用程序中集成了google plus,我可以成功login,但是我无法获取当前login的用户的电子邮件地址。我已经参考了https://developers.google.com/+/手机/ ios /并遵循所有必要的步骤login!

那么,我如何获得当前的用户邮件ID是在谷歌加login?

在这里输入图像说明

转到GTMOAuth2Authentication.m文件方法setKeysForResponseDictionary在方法结束时返回访问令牌。

accessTocken = [dict valueForKey:@"access_token"]; // access tocken pass in .pch file [accessTocken retain]; 

并在你的控制器

 - (IBAction)momentButton:(id)sender { NSString *str = [NSString stringWithFormat:@"https://www.googleapis.com/oauth2/v1/userinfo?access_token=%@",accessTocken]; NSString* escapedUrl = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",escapedUrl]]; NSString *jsonData = [[NSString alloc] initWithContentsOfURL:url usedEncoding:nil error:nil]; NSMutableDictionary *proDic = [[NSMutableDictionary alloc] init]; proDic=[jsonData JSONValue]; NSLog(@"%@",proDic); 

这是获取当前login用户的电子邮件ID最简单和最简单的方法
首先创build一个GPPSignIn类的实例variables

 GPPSignIn *signIn; 

然后在viewDidLoad初始化它

 - (void)viewDidLoad { [super viewDidLoad]; static NSString * const kClientID = @"your client id"; signIn = [GPPSignIn sharedInstance]; signIn.clientID= kClientID; signIn.scopes= [NSArray arrayWithObjects:kGTLAuthScopePlusLogin, nil]; signIn.shouldFetchGoogleUserID=YES; signIn.shouldFetchGoogleUserEmail=YES; signIn.delegate=self; } 

接下来在你的视图控制器中实现GPPSignInDelegate
在这里你可以得到login用户的电子邮件ID

 - (void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error { NSLog(@"Received Access Token:%@",auth); NSLog(@"user google user id %@",signIn.userEmail); //logged in user's email id }