谁能告诉我通过 OAuth2 生成刷新令牌的到期时间。实际上它通常返回 2 个参数访问令牌和刷新令牌。如果访问令牌过期,我们使用刷新令牌来生成新的访问令牌。但是 Google Calendar Version3,我使用刷新令牌来调用日历 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;
}