如何从谷歌+;在iOS中?

如何从谷歌+;在iOS中?,ios,objective-c,google-api,google-plus,Ios,Objective C,Google Api,Google Plus,目前在我的应用程序中,我正在从Google+获取电子邮件、谷歌ID、用户名、性别 以下是我在viewDidLoad中的代码: GPPSignIn *signIn = [GPPSignIn sharedInstance]; signIn.shouldFetchGooglePlusUser = YES; signIn.clientID = kClientId; signIn.scopes = [NSArray arrayWithObjects: kGTLAuthSc

目前在我的应用程序中,我正在从Google+获取电子邮件、谷歌ID、用户名、性别

以下是我在viewDidLoad中的代码:

GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.clientID = kClientId;
signIn.scopes = [NSArray arrayWithObjects:
                 kGTLAuthScopePlusMe,
                 kGTLAuthScopePlusUserinfoEmail,
                 kGTLAuthScopePlusLogin ,
                 nil];

signIn.shouldFetchGoogleUserID = YES;
signIn.shouldFetchGoogleUserEmail = YES;
signIn.delegate = self;
[signIn trySilentAuthentication];
下面是我的
GPPSignInDelegate
方法:

- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error
   {


    if (error) 
    {

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


        GTLServicePlus* plusService = [[GTLServicePlus alloc] init] ;
        plusService.retryEnabled = YES;


        [plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];


        [plusService executeQuery:query
                completionHandler:^(GTLServiceTicket *ticket,
                                    GTLPlusPerson *person,
                                    NSError *error) {
                    if (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);
                    }
                }];
    }


  }

我的问题是如何从Google+获取个人资料图片URL? 我提到了这一点,但没有得到准确的答案

试试这个

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",person.image.url]];
这里我添加了完整的代码

GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.clientID=@GOOGLE_PLUS_Login_ID;  // here add your ID
signIn.shouldFetchGoogleUserEmail = YES;
signIn.scopes = @[ @"profile" ];

signIn.delegate = self;

if (![signIn trySilentAuthentication])    // if it is not authenticate it re authenticate once
    [signIn authenticate];


 -(void)finishedWithAuth: (GTMOAuth2Authentication *)auth
error: (NSError *) error {
if (error) {
    // Do some error handling here.
} else {
      // NSLog(@"Received error %@", auth.userEmail);
      // NSLog(@"Received error %@", auth.accessToken);

    if ( auth.userEmail)
    {
        [[[GPPSignIn sharedInstance] plusService] executeQuery:[GTLQueryPlus queryForPeopleGetWithUserId:@"me"] completionHandler:^(GTLServiceTicket *ticket, GTLPlusPerson *person, NSError *error)
         {
 // this is for fetch profile image
 NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",person.image.url]];
             NSLog(@"%@",url);
NSLog(@"Name:%@",person.displayName);
  }];

      }

 }
}
这个怎么样

    let user: GIDGoogleUser = ...
    if user.profile.hasImage{
        let profilePicURL = user.profile.imageURLWithDimension(200).absoluteString
        print(profilePicURL)

    }

请参阅课程参考。

Swift 3

let dimension = round(thumbSize.width * UIScreen.main.scale)
let pic = userInfo.profile.imageURL(withDimension: dimension)
thumbSize.width是图像的必需宽度

let dimension = round(100 * UIScreen.main.scale)
let pic = userInfo.profile.imageURL(withDimension: dimension)

非常感谢。添加了此NSURL*url=[NSURL URLWithString:[NSString stringWithFormat:@“%@”,person.image.url]];太好了,先生@Anbu.Karthik
let dimension = round(100 * UIScreen.main.scale)
let pic = userInfo.profile.imageURL(withDimension: dimension)