Google Ads API Integration Error

645 views
Skip to first unread message

Rama G

unread,
Nov 28, 2022, 11:51:55 AM11/28/22
to Google Ads API and AdWords API Forum
Hi ,

I am using the following authorization to access Google API

 GoogleAdsConfig config = new GoogleAdsConfig()
            {
                OAuth2Mode = Google.Ads.Gax.Config.OAuth2Flow.APPLICATION,
                OAuth2ClientId = secrets.ClientId,
                OAuth2ClientSecret = secrets.ClientSecret,
                OAuth2RefreshToken = credential.Token.RefreshToken
        };

 GoogleAdsClient GACLient = new GoogleAdsClient();
            // Get the AdGroupService.
            GoogleAdsServiceClient googleAdsService = GACLient.GetService(Services.V12.GoogleAdsService);
            string searchQuery = "SELECT campaign.id, ad_group.id, ad_group.name FROM ad_group";

            // Retrieve the campaigns.
            PagedEnumerable<SearchGoogleAdsResponse, GoogleAdsRow> searchPagedResponse =
                googleAdsService.Search("XXXXXX", searchQuery);

Even though a refresh token is generated and updated, throwing the following error, Please suggest.

Status(StatusCode="Internal", Detail="Error starting gRPC call. TokenResponseException: Error:"invalid_request", Description:"Missing required parameter: refresh_token", Uri:""", DebugException="Google.Apis.Auth.OAuth2.Responses.TokenResponseException: Error:"invalid_request", Description:"Missing required parameter: refresh_token", Uri:""
   at Google.Apis.Auth.OAuth2.Responses.TokenResponse.FromHttpResponseAsync(HttpResponseMessage response, IClock clock, ILogger logger)
   at Google.Apis.Auth.OAuth2.Requests.TokenRequestExtenstions.ExecuteAsync(TokenRequest request, HttpClient httpClient, String tokenServerUrl, CancellationToken taskCancellationToken, IClock clock, ILogger logger)
   at Google.Apis.Auth.OAuth2.Flows.AuthorizationCodeFlow.FetchTokenAsync(String userId, TokenRequest request, CancellationToken taskCancellationToken)
   at Google.Apis.Auth.OAuth2.Flows.AuthorizationCodeFlow.FetchTokenAsync(String userId, TokenRequest request, CancellationToken taskCancellationToken)
   at Google.Apis.Auth.OAuth2.Flows.AuthorizationCodeFlow.RefreshTokenAsync(String userId, String refreshToken, CancellationToken taskCancellationToken)
   at Google.Apis.Auth.OAuth2.UserCredential.RefreshTokenAsync(CancellationToken taskCancellationToken)
   at Google.Apis.Auth.OAuth2.TokenRefreshManager.RefreshTokenAsync()
   at Google.Apis.Auth.OAuth2.TokenRefreshManager.GetAccessTokenForRequestAsync(CancellationToken cancellationToken)
   at Google.Apis.Auth.OAuth2.UserCredential.GetAccessTokenWithHeadersForRequestAsync(String authUri, CancellationToken cancellationToken)
   at Grpc.Auth.GoogleAuthInterceptors.<>c__DisplayClass3_0.<<FromCredential>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Grpc.Net.Client.Internal.GrpcProtocolHelpers.ReadCredentialMetadata(DefaultCallCredentialsConfigurator configurator, GrpcChannel channel, HttpRequestMessage message, IMethod method, CallCredentials credentials)
   at Grpc.Net.Client.Internal.GrpcCall`2.ReadCredentials(HttpRequestMessage request)
   at Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage request, Nullable`1 timeout)")






Zweitze

unread,
Nov 28, 2022, 5:35:19 PM11/28/22
to Google Ads API and AdWords API Forum
This is C# / .NET library?
Here are my suggestions to improve:

GoogleAdsConfig config = new GoogleAdsConfig()
            {
                OAuth2Mode = Google.Ads.Gax.Config.OAuth2Flow.APPLICATION,
                OAuth2ClientId = secrets.ClientId,
                OAuth2ClientSecret = secrets.ClientSecret,
                OAuth2RefreshToken = credential.Token.RefreshToken
        };
config.LoginCustomerId = /* The top level MCC where your account resides in */;
 GoogleAdsClient GACLient = new GoogleAdsClient(config);
            // Get the AdGroupService.

The rest is the same.

Your problem was mainly constructing the GoogleAdsClient instance. If you use the constructor without any arguments (as you did), these arguments will be retrieved from your configuration file app.config. Using the constructor with the config argument (the improvement) ensures the settings you pass are used.

The other highlight, about LoginCustomerId, would probably be the next problem you run into.

Google Ads API Forum Advisor

unread,
Nov 28, 2022, 8:47:58 PM11/28/22
to zwe...@gmail.com, adwor...@googlegroups.com
Hi Everyone,

Thank you for reaching out to us.

Upon checking your logs, I can see that you are encountering "invalid_request", "Missing required parameter: refresh_token. Kindly note that in the App.config file, you have to specify the refresh token along with other needed OAuth2 credentials. You may refer to this guide for the steps on how you can regenerate credentials and refresh tokens.

The refresh token is generated as shown here . It should be generated at the same level as your other credentials (client id and secret).

If you are still having an issue after following the above mentioned points, please share the updated complete request and response logs with request ID so we can take a closer look at the issue.

You may then send the requested logs via the Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

@Zweitze -Thank you for your suggestion, this is well appreciated.

Best regards,
Google Logo
Heidi
Google Ads API Team
 
​​​​​​​

ref:_00D1U1174p._5004Q2gg4yi:ref
Reply all
Reply to author
Forward
0 new messages