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.

On Monday, November 28, 2022 at 5:51:55 PM UTC+1 [email protected] wrote:

> 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)")
>
>
>
>
>
>
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/df73847a-9db6-40c8-8237-8ad99ff1b922n%40googlegroups.com.

Reply via email to