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

前端 未结 3 1323
猫巷女王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

    - (void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error {
        NSLog(@"Received Error %@ and auth object==%@", error, auth);
    
        if (error) {
            // Do some error handling here.
        } else {
            [self refreshInterfaceBasedOnSignIn];
    
            GTLQueryPlus *query = [GTLQueryPlus queryForPeopleGetWithUserId:@"me"];
    
            NSLog(@"email %@ ", [NSString stringWithFormat:@"Email: %@",[GPPSignIn sharedInstance].authentication.userEmail]);
            NSLog(@"Received error %@ and auth object %@",error, auth);
    
            // 1. Create a |GTLServicePlus| instance to send a request to Google+.
            GTLServicePlus* plusService = [[GTLServicePlus alloc] init] ;
            plusService.retryEnabled = YES;
    
            // 2. Set a valid |GTMOAuth2Authentication| object as the authorizer.
            [plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];
    
            // 3. Use the "v1" version of the Google+ API.*
            plusService.apiVersion = @"v1";
            [plusService executeQuery:query
                    completionHandler:^(GTLServiceTicket *ticket,
                                        GTLPlusPerson *person,
                                        NSError *error) {
                if (error) {
                    //Handle Error
                } else {
                    NSLog(@"Email= %@", [GPPSignIn sharedInstance].authentication.userEmail);
                    NSLog(@"GoogleID=%@", person.identifier);
                    NSLog(@"User Name=%@", [person.name.givenName stringByAppendingFormat:@" %@", person.name.familyName]);
                    NSLog(@"Gender=%@", person.gender);
                }
            }];
        }
    }
    

    Hope, this will help you

提交回复
热议问题