简体   繁体   中英

iOS - Can't get basic user info from Google profile

I want to retrieve basic information like name, email from Google account. Here Get User information after successful authentication with Oauth2 I've found tip to change the property "shouldFetchGoogleUserProfile" to YES, but it's not accessible for me.

GTMOAuth2ViewControllerTouch *viewController;
                viewController = [[GTMOAuth2ViewControllerTouch alloc] initWithScope:scope
                                                            clientID:kMyClientID
                                                        clientSecret:kMyClientSecret
                                                    keychainItemName:kKeychainItemName
                                                            delegate:self
                                                     finishedSelector:@selector(viewController:finishedWithAuth:error:)];

// error - can't access property "shouldFetchGoogleUserProfile"
   viewController.signIn.shouldFetchGoogleUserProfile = YES;

[[self navigationController] pushViewController: viewController
                                       animated:YES];

I cannot also get the result after sign-in

  - (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
  finishedWithAuth:(GTMOAuth2Authentication *)auth
             error:(NSError *)error {
 if (!error) {
      // userProfile - not accessible
     // NSDictionary *profile = viewController.signIn.userProfile;
  } else {
     NSLog(@"Failure %@", error);
 }
 } 

I had this same issue. Add

#import "GTL/GTMOAuth2SignIn.h"

to the bridging header which is the class for signIn.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM