目前,我的代码在过期时不会自动刷新我的访问代码。我不知道如何在我自己的代码中实现这篇文章中的代码(如何通过 .NET 中的 Google Drive SDK 使用刷新令牌生成访问令牌?)。
我的代码:
private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
{
// Get the auth URL:
IAuthorizationState state = new AuthorizationState(new[] { "https://www.googleapis.com/auth/yt-analytics.readonly" });
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri = arg.RequestUserAuthorization(state);
// Request authorization from the user (by opening a browser window):
Process.Start(authUri.ToString());
Console.Write(" Authorization Code: ");
string authCode = Console.ReadLine();
Console.WriteLine();
// Retrieve the access token by using the authorization code:
return arg.ProcessUserAuthorization(authCode, state);
}
具体来说,我没有得到这条线。如何保存我的刷新令牌并将其插入 state.RefreshToken?我假设我需要在返回状态之前填充这两行(state.RefreshToken 和 arg.RefreshToken(state))?
state.RefreshToken = "<refresh token previously saved>";