使用Google+ iOS API如何登录用户的个人资料详情? [英] Using Google+ iOS API how to get logged in user's profile details?

查看:106
本文介绍了使用Google+ iOS API如何登录用户的个人资料详情?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功从iPhone应用程序成功登录google plus。但是如何登录用户的详细信息?例如个人资料ID,电子邮件等。

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.

我试过这个,
Stackoverflow回答类似的问题但我是无法让它运作。在该示例中,这里究竟是什么传递给accessTocken,

I tried this, Stackoverflow answer for a similar question but I was unable to get it working. In that sample what exactly is being passed to accessTocken here,

NSString *str =  [NSString stringWithFormat:@"https://www.googleapis.com/oauth2/v1/userinfo?access_token=%@",accessTocken];

我在中实现了该代码 - (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
错误:(NSError *)错误
{}
方法。但是 auth.accessToken 返回一个空值。

I've implemented that code in - (void)finishedWithAuth: (GTMOAuth2Authentication *)auth error: (NSError *) error { } method. however auth.accessToken returns a null value.

所以我不能使用auth.accessToken来附加该URL。有没有其他方法来完成这项工作?

so I can not use auth.accessToken to append that URL. Is there any other way to get this done?

推荐答案

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

希望,这会对你有帮助

这篇关于使用Google+ iOS API如何登录用户的个人资料详情?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆