我使用了Google Developers Documentation但我无法使用UserID
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.0f/255.0f green:102.0f/255.0f blue:204.0f/255.0f alpha:100.0];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
signIn = [GPPSignIn sharedInstance];
//您之前在“初始化Google+客户端”步骤
中设置了kClientId signIn.clientID = kClientId;
[signIn setScopes:[NSArray arrayWithObject: @"https://www.googleapis.com/auth/plus.me"]];
//取消注释以获取用户的电子邮件
signIn.shouldFetchGoogleUserEmail = YES;
//取消注释以获取用户的ID
signIn.shouldFetchGoogleUserID = YES;
signIn.delegate = self;
Gplusbtn = [[GPPSignInButton alloc] init];
Gplusbtn.frame = CGRectMake([simod CG:10], [simod CG:125], [simod CG:300], [simod CG:30]);
Gplusbtn.style=kGPPSignInButtonStyleWide;
Gplusbtn.enabled = YES;
[self.view addSubview:Gplusbtn];
}
- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
if (error) {
_signInAuthStatus.text =
[NSString stringWithFormat:@"Status: Authentication error: %@", error];
return;
}
NSLog(@"ID:%@", signIn.userID);
}
NSLog显示ID :( null)
那么代码有问题,如何解决?
答案 0 :(得分:1)
你只需要使用
像这样:[GPPSignIn sharedInstance]
NSString * gpUserID = [GPPSignIn sharedInstance].userID;