You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code is used in the example for fetching refresh tokens in a .NET console application.
private static void DoAuth2Authorization(AdWordsUser user) {
// Since we are using a console application, set the callback url to null.
user.Config.OAuth2RedirectUri = null;
AdsOAuthProviderForApplications oAuth2Provider =
(user.OAuthProvider as AdsOAuthProviderForApplications);
// Get the authorization url.
string authorizationUrl = oAuth2Provider.GetAuthorizationUrl();
Console.WriteLine("Open a fresh web browser and navigate to \n\n{0}\n\n. You will be " +
"prompted to login and then authorize this application to make calls to the " +
"AdWords API. Once approved, you will be presented with an authorization code.",
authorizationUrl);
// Accept the OAuth2 authorization code from the user.
Console.Write("Enter the authorization code :");
string authorizationCode = Console.ReadLine();
// Fetch the access and refresh tokens.
oAuth2Provider.FetchAccessAndRefreshTokens(authorizationCode);
}
}
The issue is that the example says to
Set the callback url to null
but this caused the application to throw this error when running the application:
Value cannot be null.
Parameter name: Looks like your application is not configured to use OAuth2 properly. Required OAuth2 parameter RedirectUri is missing. You may run Common\\Utils\\OAuth2TokenGenerator.cs to generate a default OAuth2 configuration.
I have discovered that rather than setting user.Config.OAuth2RedirectUri = null, you avoid this issue entirely by just not setting the uri at all.
The working code example
private static void DoAuth2Authorization(AdWordsUser user)
{
// Since we are using a console application, set the callback url to null.
// Dont do this - > user.Config.OAuth2RedirectUri = null;
AdsOAuthProviderForApplications oAuth2Provider =
(user.OAuthProvider as AdsOAuthProviderForApplications);
// Get the authorization url.
string authorizationUrl = oAuth2Provider.GetAuthorizationUrl();
Console.WriteLine("Open a fresh web browser and navigate to \n\n{0}\n\n. You will be " +
"prompted to login and then authorize this application to make calls to the " +
"AdWords API. Once approved, you will be presented with an authorization code.",
authorizationUrl);
// Accept the OAuth2 authorization code from the user.
Console.Write("Enter the authorization code :");
string authorizationCode = Console.ReadLine();
// Fetch the access and refresh tokens.
oAuth2Provider.FetchAccessAndRefreshTokens(authorizationCode);
}
Either I was misunderstanding something, or this wiki documentation is inaccurate and caused a huge headache.
I hope this is the appropriate place to raise the issue.
The text was updated successfully, but these errors were encountered:
I think the following Wiki Page has some inaccuracy in it's code examples
Wiki Page: https://github.com/googleads/googleads-dotnet-lib/wiki/API-access-using-own-credentials-(installed-application-flow)
The following code is used in the example for fetching refresh tokens in a .NET console application.
The issue is that the example says to
but this caused the application to throw this error when running the application:
I have discovered that rather than setting
user.Config.OAuth2RedirectUri = null
, you avoid this issue entirely by just not setting the uri at all.The working code example
Either I was misunderstanding something, or this wiki documentation is inaccurate and caused a huge headache.
I hope this is the appropriate place to raise the issue.
The text was updated successfully, but these errors were encountered: