Search code examples
iphoneiosios6google-plusgoogle-plus-one

I have integrated google plus in my IOS App ,But I am not able to get email Id of current user that is logged In


I have integrated google plus in my ios app ,I am able to sign in successfully but I am not able to get email Id of current user that is logged in. I have referd to https://developers.google.com/+/mobile/ios/ and have followed all the steps that are necessary for sign in!

So, How i get current User Mail ID that is Login In Google plus?

enter image description here


Solution

  • go to GTMOAuth2Authentication.m file method setKeysForResponseDictionary in dic returns access token at end of method.

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

    and in your controller

    - (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);