Using Google+ iOS API how to get logged in user's profile details?

前端 未结 3 1325
猫巷女王i
猫巷女王i 2021-01-31 12:17

I\'ve managed to successfully log in to google plus from an iPhone app. But how to get logged in user\'s details? such as profile id, email etc.

I tried this, Stackoverf

3条回答
  •  广开言路
    2021-01-31 13:08

    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
     }
    

提交回复
热议问题