iphone - 使用Oauth2成功认证后获取用户信息

标签 iphone ios oauth-2.0 google-oauth

在我的iPhone应用程序中,我正在使用googlet登录到Oauth2,正在关注this insturction并成功登录

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


if(!error)
    {
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Success Authorizing with Google"

                                                         message:nil
                                                        delegate:nil
                                               cancelButtonTitle:@"OK"
                                               otherButtonTitles:nil];
        [alert show];
    }

我正在使用https://www.googleapis.com/auth/userinfo.profile范围的GTMOAuth2Authentication,现在我想获取用户的基本信息,例如姓名,年龄,电子邮件等。

那么如何获得所有细节呢?
我搜索了很多,但没有找到任何东西。

可能是How to get OAuth2 user information in iOS?的问题重复,但这也无济于事。

请帮忙

最佳答案

默认情况下,GTMOAuth2ViewControllerTouch viewController将获取用户的电子邮件,但不会获取用户个人资料的其余部分。
可以在登录前通过设置以下属性来请求Google服务器的完整个人资料:

GTMOAuth2ViewControllerTouch *viewController;viewController.signIn.shouldFetchGoogleUserProfile = YES;
登录后将以的身份使用个人资料

   NSDictionary *profile = viewController.signIn.userProfile;

并获取其他信息,您必须更改scope字符串,然后再次开始获取。

这是一些范围网址
@"https://www.googleapis.com/auth/plus.me"@"https://www.googleapis.com/auth/userinfo.email"@"https://www.googleapis.com/auth/tasks"

关于iphone - 使用Oauth2成功认证后获取用户信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17989853/

相关文章:

ios - iphone 6 的编译错误(没有要编译的架构)

iOS CSR 证书未正确生成

ios - 如何解析 firebase FDataSnapshot 对象?

oauth-2.0 - 通过 Slack OAuth 进行身份验证后如何识别现有用户?

iphone - 长时间运行的操作(用于更新当前显示的iphone TableView 中的数据)的最佳实践是什么?

ios - 无效时 NSTimer 在 Iphone 上因 EXC_BAD_ACCESS 而崩溃

ios - 从服务器获取 JSON 文件时的内容丢失

IOS App内存使用标准

java - RestController 在 oauth2 Spring Boot 中不起作用

grails - Grails: token 中的Oauth Twitter用户ID