【发布时间】:2013-06-03 13:37:57
【问题描述】:
在 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");
}
}
编辑:回应 Ashim 的评论 ...
我在应用程序委托中有这个:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
我必须在这个函数中编写任何特定的代码吗?
【问题讨论】:
-
你在你的 AppDelegate 中实现了方法 - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url 吗?
-
我在应用程序委托中有这个: - (BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication: (NSString *)sourceApplication annotation: (id)annotation { return [GPPURLHandler handleURL:url sourceApplication:sourceApplication 注解:注解];我必须在这个函数中编写任何特定的代码吗?
-
这是一个小问题,但您可能应该使用googleapis.com/auth/plus.login 范围。
-
@class : 我会试试然后回复你。
-
@class :它不起作用。
标签: ios xcode authentication google-plus google-authentication