Google Ads API Integration Error - GRPC Error

2024-04-12 Thread Márcio Duarte
Hi there, 

I'm trying to integrate with Google Ads API using the available .NET 
package (Google.Ads.GoogleAds latest version - 19.0.1) on a .NET 8 project.

I'm setting up the API out of the samples provided, and currently getting a 
very generic GRPC error which I'm not able to figure out what is going on.

*Message: *Status(StatusCode="Internal", Detail="Internal error 
encountered.")
*Stacktrace: *   at 
Google.Ads.Gax.Interceptors.StreamingRpcInterceptor`1.MoveNext(CancellationToken
 
cancellationToken)
   at 
Google.Api.Gax.Grpc.AsyncResponseStream`1.MoveNextAsync(CancellationToken 
cancellationToken)
   at 
Google.Ads.GoogleAds.V16.Services.GoogleAdsServiceClient.<>c__DisplayClass32_0.d.MoveNext()
--- End of stack trace from previous location ---
   at Program.<>c.<<$>b__0_0>d.MoveNext() in \Program.cs:line 61

The sample application is as follows:

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();


app.MapGet("/sample", async () =>
{
  var config = new GoogleAdsConfig() {
 OAuth2Mode = Google.Ads.Gax.Config.OAuth2Flow.APPLICATION,
 DeveloperToken = "",
 OAuth2ClientId = "",
 OAuth2ClientSecret = "",
 LoginCustomerId = "",
 LinkedCustomerId = "",
 OAuth2RefreshToken =
""
  };

  // Create a Google Ads client.
  var client = new GoogleAdsClient(config);

  // Create the required service.
  var service =
 client.GetService(Services.V16.GoogleAdsService);

  // Create a query that will retrieve all campaigns.
  var query = $@"SELECT
campaign.id,
campaign.name,
campaign.network_settings.target_content_network
FROM campaign
ORDER BY campaign.id";

  var request = new SearchGoogleAdsStreamRequest();
  request.Query = query;

  try {

 await service.SearchStreamAsync(request, (response) => {

foreach (var googleAdsRow in response.Results) {
   Console.WriteLine("Campaign with ID {0} and name '{1}' was 
found.",
  googleAdsRow.Campaign.Id, googleAdsRow.Campaign.Name);
}

 });
  }
  catch (GoogleAdsException e) {
 Console.WriteLine("Failure:");
 Console.WriteLine($"Message: {e.Message}");
 Console.WriteLine($"Failure: {e.Failure}");
 Console.WriteLine($"Request ID: {e.RequestId}");
 throw;
  }
  catch (Exception ex) {
 
  }   
})
.WithName("GetSample")
.WithOpenApi();

app.Run();


Is there any other setup needed for GRPC to work as expected?
Would you be able to help me, please?

Much appreciated.


-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/cdd90fa4-174f-4d3e-bf2e-84bccc3b6ec9n%40googlegroups.com.


Re: Google Ads API Integration Error

2022-11-28 Thread Zweitze
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 ramag...@gmail.com 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 
> searchPagedResponse =
> googleAdsService.Search("XX", 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.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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 AdW

Google Ads API Integration Error

2022-11-28 Thread Rama G
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 
searchPagedResponse =
googleAdsService.Search("XX", 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.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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/70085133-c097-4b97-b950-b0eb04b88645n%40googlegroups.com.