At the moment my code does not automatically refresh my access code when it expires. I'm at a loss at how to implement the code from this post (How to generate access token using refresh token through Google Drive SDK in .NET?) inside my own code.
My code:
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);
}
Specifically I don't get this line. How to save my refresh token and insert it in state.RefreshToken? I assume I need to cram those 2 lines (state.RefreshToken and arg.RefreshToken(state)) just before return state?
state.RefreshToken = "<refresh token previously saved>";