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

StackOverflow https://stackoverflow.com/questions/13302904

Question

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

Était-ce utile?

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

Autres conseils

This is the easiest and the simplest way of fetching the current logged in user's email id
first create an instance variable of GPPSignIn class

GPPSignIn *signIn;

then initialize it in the 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;

   }

next implement the GPPSignInDelegate in your view controller
here you can get the logged in user's email 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
  }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top