Tos*_*lji 1 iphone ios oauth-2.0 google-oauth
在我的iPhone应用程序中,我正在使用谷歌登录使用Oauth2,我正在遵循此操作并成功登录
- (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];
}
Run Code Online (Sandbox Code Playgroud)
我正在使用https://www.googleapis.com/auth/userinfo.profile范围GTMOAuth2Authentication,现在我想获取用户的基本信息,如姓名,年龄,电子邮件等.
那我怎么能得到所有细节?
我搜索很多,但没有找到任何东西.
可能重复的问题如何在iOS中获取OAuth2用户信息?,但它也没有帮助.
请帮忙
默认情况下,GTMOAuth2ViewControllerTouch viewController将获取用户的电子邮件,但不会获取用户配置文件的其余部分.
登录前可以通过设置此属性从Google服务器请求完整的个人资料:
GTMOAuth2ViewControllerTouch *viewController;
viewController.signIn.shouldFetchGoogleUserProfile = YES;
登录后,该个人资料将可用
NSDictionary *profile = viewController.signIn.userProfile;
Run Code Online (Sandbox Code Playgroud)
并获取其他信息,您必须更改scope字符串并再次开始提取.
这里有一些范围网址
@"https://www.googleapis.com/auth/plus.me"
@"https://www.googleapis.com/auth/userinfo.email"
@"https://www.googleapis.com/auth/tasks"