Google Ads API Integration Error - GRPC Error

56 views
Skip to first unread message

Márcio Duarte

unread,
Apr 12, 2024, 5:14:10 PM4/12/24
to Google Ads API and AdWords API Forum
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.<<SearchStreamAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Program.<>c.<<<Main>$>b__0_0>d.MoveNext() in xxxx\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 = "xxxx",
         OAuth2ClientId = "xxxx",
         OAuth2ClientSecret = "xxxx",
         LoginCustomerId = "xxxx",
         LinkedCustomerId = "xxxx",
         OAuth2RefreshToken =
            "xxxx"
      };

      // 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.


Google Ads API Forum Advisor

unread,
Apr 15, 2024, 1:12:05 PM4/15/24
to marcio....@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads API support team.

From the provided information, it appears that you are encountering internal error. Kindly note that the 'INTERNAL_ERROR' occurs when something unexpected happened while processing the request. The common cause could be the API isn't functioning correctly. However, this is transient in nature and the API request will work again when retrying it after 30 seconds or some time. I have tried to replicate the issue but I got a successful response upon making the API call. You may also retry any requests that failed with this error, using an exponential backoff schedule for the retries. Here is a code example demonstrating how to implement an exponential back off strategy.

If you are still facing the internal error, then please provide us with the following details :
  • How much time did you wait before retry of a request
  • Timestamp of the API call when you got the internal error
  • Complete API logs (request and response logs with request-id and request header) generated at your end
 This message is in relation to case "ref:!00D1U01174p.!5004Q02tP5E1:ref" (ADR-00231011)

Thanks,
 
Google Logo Google Ads API Team


Reply all
Reply to author
Forward
0 new messages