【发布时间】:2016-12-27 11:53:14
【问题描述】:
我通过该方法获得访问令牌:
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuth2Authentication *)authResult
error:(NSError *)error {
if (error != nil) {
[self showAlert:@"Authentication Error" message:error.localizedDescription];
self.service.authorizer = nil;
}
else {
self.service.authorizer = authResult;
NSLog(@"Token: %@ id: %@", authResult.accessToken, authResult.userID);
[self makeGmailLabelVisibleWithToken:authResult.accessToken]; //make an authorized request to gmailAPI with the access token
[self dismissViewControllerAnimated:YES completion:nil];
}
}
所以,经过身份验证后它工作正常,但过了一段时间它停止工作(我猜是因为令牌已过期)。另外,如果我使用
[authResult refreshToken]
而不是
authResult.accessToken
这行不通。
那么刷新 Gmail 访问令牌的正确方法是什么,我应该使用哪种方法呢?
P.S:documentation 表示
- (void) refreshTokensWithHandler:(GIDAuthenticationHandler)handler
应该有帮助,但我没有找到任何样本。
【问题讨论】:
标签: ios objective-c gmail google-oauth gmail-api