在我的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/