Google Plus iOS SDK not refreshing expired token

♀尐吖头ヾ 提交于 2019-12-12 04:56:40

问题


I have a problem, which might have a so simple solution, that I am not able to see it.

I installed the Google Plus iOS SDK into my app, and got my app running with Google very nice.

Google Plus iOS SDK

BUT, after one hour, the token is expiring, and I don't find a way to renew it.

- (void)renewGoogleToken {
    GPPSignIn *gppSignIn                        = [GPPSignIn sharedInstance];
    gppSignIn.shouldFetchGooglePlusUser         = YES;
    gppSignIn.shouldFetchGoogleUserEmail        = YES;
    gppSignIn.clientID                          = [DSUtils getGoogleClientID];
    gppSignIn.scopes                            = @[@"https://www.googleapis.com/auth/plus.login",
                                                @"https://www.googleapis.com/auth/calendar"];
    gppSignIn.delegate                          = self;

    BOOL success                                = [gppSignIn trySilentAuthentication];  }

I call this method initially, when I want to login with Google+. After one hour, when token is about to expire, I call this method again, but I receive same token, which is about to expire.

Anybody can help me please? I searched intensely on google, and could not find a solution. The SDK Docs doesn't say anything about renewing, which is strange. Is token refreshed automatically?

Please help, Thanks.


回答1:


The object you get back is a GTMOAuth2Authentication. If being used in a regular Google service request, it should automatically be refreshed automatically if needed. However, if you need to force a refresh you can request authorization of a nil request:

[auth authorizeRequest:nil
          delegate:self     
 didFinishSelector:@selector(authentication:request:finishedWithError:)];

Or with blocks

[auth authorizeRequest:nil 
 completionHandler:^(NSError *error) { //...
}];


来源:https://stackoverflow.com/questions/29720107/google-plus-ios-sdk-not-refreshing-expired-token

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!