【发布时间】:2015-10-28 02:43:54
【问题描述】:
我无法使用[self isAuthorized] 来确认我之前获得的访问令牌。
每次我使用适用于 iOS 的 Google Drive SDK 登录时:
// Creates the auth controller for authorizing access to Google Drive.
-(GTMOAuth2ViewControllerTouch *)createAuthController {
GTMOAuth2ViewControllerTouch *authController;
authController = [[GTMOAuth2ViewControllerTouch alloc] initWithScope:scopes
clientID:kClientID
clientSecret:kClientSecret
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
return authController;
}
认证完成后,没有错误,应该正确保存访问令牌
// Handle completion of the authorization process, and updates the Drive service
// with the new credentials.
-(void)viewController:(GTMOAuth2ViewControllerTouch *)viewController finishedWithAuth:(GTMOAuth2Authentication *)authResult error:(NSError *)error {
if (error != nil)
{
//[self showAlert:@"Authentication Error" message:error.localizedDescription];
self.driveService.authorizer = nil;
}
else
{
self.driveService.authorizer = authResult;
}
}
我使用 NSLog 来确保我收到了访问令牌并且确实收到了。
-(BOOL)isAuthorized {
NSString *oauthToken = [((GTMOAuth2Authentication *)self.driveService.authorizer) accessToken];
NSLog(@"oauthToken: %@", oauthToken);
return [((GTMOAuth2Authentication *)self.driveService.authorizer) canAuthorize];
}
但是当我查看我是否被授权时,没有保存令牌(oauthToken 为 NULL),我需要再次登录。
N.B:在 iOS 9 之前它在过去工作。我不知道它是否相关。
谢谢 文森特
【问题讨论】:
标签: ios google-drive-api