This is an existing console application that used Adwords to generate its refresh token. Since Adword is deprecated,
Below is my static function to generate new refresh token:
public async static Task UserAuth()
{
string id = "
xxxxxxxxx.apps.googleusercontent.com";
string secret = "xxxxxxxxxxxx";
ClientSecrets secrets = new ClientSecrets()
{
ClientId = id,
ClientSecret = secret
};
string[] scopes = { "
https://www.googleapis.com/auth/adwords" };
var flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = secrets,
Scopes = scopes,
DataStore = new FileDataStore("GoogleAdsTokenStore")
});
var authCodeUri = flow.CreateAuthorizationCodeRequest("urn:ietf:wg:oauth:2.0:oob").Build();
Console.WriteLine("Authorize the application by visiting the following URL:");
Console.WriteLine(authCodeUri.AbsoluteUri);
Console.WriteLine("Enter the authorization code:");
// Read the authorization code from the console
string code = Console.ReadLine();
// Exchange the authorization code for tokens
var token = await flow.ExchangeCodeForTokenAsync("user", code, "urn:ietf:wg:oauth:2.0:oob", CancellationToken.None);
// Output the token information
Console.WriteLine("Access token: " + token.AccessToken);
Console.WriteLine("Refresh token: " + token.RefreshToken);
Console.WriteLine("Token expires at: " + token.ExpiresInSeconds);
//}
}
Please remember, it is a console application.