任何人都可以告诉我通过OAuth2生成刷新令牌的到期时间。实际上它通常会返回2个参数访问令牌和刷新令牌。我们使用刷新令牌,以便在访问令牌过期时生成新的访问权限。但谷歌日历版本3,我使用刷新令牌来调用日历API。但是在这里我遇到令牌过期的问题。所以任何人都可以建议我在令牌到期时我该怎么办。据我所知,刷新令牌没有到期时间。请使用刷新令牌检查以下代码以创建日历服务: -
private CalendarService CreateService(string token)
{
KeyValuePair<string, string> credentials = Common.Get3LOCredentials();
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier = credentials.Key;
provider.ClientSecret = credentials.Value;
var auth = new Google.Apis.Authentication.OAuth2.OAuth2Authenticator<NativeApplicationClient>(provider, (p) => GetAuthorization(provider, token));
CalendarService service = new CalendarService(new BaseClientService.Initializer()
{
Authenticator = auth,
ApiKey = ConfigurationManager.AppSettings["APIkey"].ToString(),
GZipEnabled = false
});
return service;
}
private static IAuthorizationState GetAuthorization(NativeApplicationClient arg, String Refreshtoken)
{
IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() });
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
state.RefreshToken = Refreshtoken;
return state;
}
答案 0 :(得分:2)
刷新令牌不会过期,但可以撤销它们。您,令牌处理程序可以revoke the token yourself programatically或最终用户可以revoke the token in their account settings。确保您正确using the refresh token to get a new access token并且您没有尝试使用已过期的访问令牌。
您可以编辑问题以显示您遇到的确切错误吗?