在 iOS 应用程序中,我使用下面的代码在另一个视图控制器中检索用户的身份验证,该用户已经使用 google plus 登录 API 登录:
GTMOAuth2ViewControllerTouch *viewController = [[GTMOAuth2ViewControllerTouch alloc]
initWithScope:@"https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.me"
clientID:CLIENT_ID
clientSecret:CLIENT_SECRET
keychainItemName:NAME
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
[[self navigationController] pushViewController:_googlePlusCtrl animated:YES];
但是当我在代码下面运行时, viewController.authentication.accessToken 给出 nil 值, viewController.authentication 也给出 nil 值。
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error
{
if (error != nil) {
// Authentication failed
NSLog(@"failed");
} else {
// Authentication succeeded
NSLog(@"Success");
}
}
编辑:回应阿希姆的评论......
我在应用程序委托中有这个:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
我是否必须在此函数中编写任何特定代码?