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
Asked Answered
L

2

1

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

Landscape answered 9/11, 2012 at 5:59 Comment(1)
Any ideas on how to integrate g+ hangout (video calling) in our ios application. I have gone through the official documentation of hangouts. But I see xml files as source code examples. How do I integrate it, is there a proficient tutorial...please help me, thanks :)Ascendancy
A
8

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);
Allusive answered 10/11, 2012 at 7:50 Comment(2)
hi Hardik thanks for your answer. I am able to get user email and id but i cant get user name. any idea ?Ochlocracy
@Hardik Mamotra Any ideas on how to integrate g+ hangout (video calling) in our ios application. I have gone through the official documentation of hangouts. But I see xml files as source code examples. How do I integrate it, is there a proficient tutorial...please help me, thanks :)Ascendancy
A
5

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
  }
Aminaamine answered 10/4, 2013 at 10:28 Comment(1)
It would be better to check error variable in finishedWithAuth.Heterochromosome

© 2022 - 2024 — McMap. All rights reserved.