googleads / google-ads-dotnet

This project hosts the .NET client library for the Google Ads API.
https://developers.google.com/google-ads/api
Apache License 2.0
73 stars 97 forks source link

StatusCode": 14, "Details": "Name resolution failure", "RequestId": null #59

Closed Swapygit closed 5 years ago

Swapygit commented 5 years ago

I am running the GetCampaign.cs file in google ads examples project but I am getting the following error.

StatusCode": 14, "Details": "Name resolution failure", "RequestId": null

Customer Id="5826317268"

AnashOommen commented 5 years ago

Hi,

Is the google ads endpoint reachable from uour server? What happens if you try reaching https://googleads.googleapis.com/v0/customers/1234567890/campaignBudgets:mutate ? Does that give you a 404?

Swapygit commented 5 years ago

Hi,

I am getting 401 Request is missing required authentication credential. I followed the google ads api documentation and enable google ads api in my google API library. But now I am getting the following error

Status(StatusCode=Unavailable, Detail="channel is in state TRANSIENT_FAILURE")

Kindly help

AnashOommen commented 5 years ago

Looks to me like there are connectivity issues from your code to the API server. The error code you received is documented here:

https://github.com/grpc/grpc/blob/master/doc/connectivity-semantics-and-api.md

Does your environment need any other additional configuration tonwork with HTTP/2 (e.g. proxy)?

Swapygit commented 5 years ago

Hi Here is my code,

public class GetCampaigns : ExampleBase {

    /// <summary>
    /// The Google Ads API scope.
    /// </summary>
    private const string GOOGLE_ADS_API_SCOPE = "https://www.googleapis.com/auth/adwords";
    /// <summary>
    /// The page size to be used by default.
    /// </summary>
    private const int PAGE_SIZE = 100;

    /// <summary>
    /// Main method, to run this code example as a standalone application.
    /// </summary>
    /// <param name="args">The command line arguments.</param>
    public static void Main(string[] args)
    {
        GetCampaigns codeExample = new GetCampaigns();

        Console.WriteLine(codeExample.Description);

        // The Google Ads customer ID for which the call is made.
        long customerId = long.Parse(INSERT_YOUR_customerId_HERE);

        codeExample.Run(new GoogleAdsClient(), customerId);
    }

    /// <summary>
    /// Returns a description about the code example.
    /// </summary>
    public override string Description
    {
        get
        {
            return "This code example gets all campaigns. To add campaigns, run " +
                "AddCampaigns.cs.";
        }
    }

    /// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="client">The Google Ads client.</param>
    /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
    public void Run(GoogleAdsClient client, long customerId)
    {
        // Get the GoogleAdsService.
        GoogleAdsServiceClient googleAdsService = client.GetService(
            Services.V1.GoogleAdsService);

        // Create a request that will retrieve all campaigns using pages of the specified
        // page size.
        SearchGoogleAdsRequest request = new SearchGoogleAdsRequest()
        {
            PageSize = PAGE_SIZE,
            Query = @"SELECT
                        campaign.id,
                        campaign.name,
                        campaign.network_settings.target_content_network
                    FROM campaign
                    Where segments.date DURING LAST_30_DAYS
                    ORDER BY campaign.id",
            CustomerId = customerId.ToString()
        };
        //Where segments.date DURING LAST_30_DAYS

        try
        {
            // Issue the search request.
            PagedEnumerable<SearchGoogleAdsResponse, GoogleAdsRow> searchPagedResponse =
                googleAdsService.Search(request);

            foreach (SearchGoogleAdsResponse response in searchPagedResponse.AsRawResponses())
            {
                Console.WriteLine(response.FieldMask.Paths);
                foreach (GoogleAdsRow googleAdsRow in response.Results)
                {
                    Console.WriteLine("Campaign with ID {0} and name '{1}' was found.",
                        googleAdsRow.Campaign.Id, googleAdsRow.Campaign.Name);
                }
            }
            // Iterate over all rows in all pages and prints the requested field values for the
            // campaign in each row.
            foreach (GoogleAdsRow googleAdsRow in searchPagedResponse)
            {
                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}");
        }
    }
}
AnashOommen commented 5 years ago

Hi,

I don’t doubt your code snippet; I rather suspect your machine configuration when connecting to the internet. Do you have another machine where you can try out this code example?

If the issue persists, pls share a zip of a demo project with me (anash@google.com) and I will try replicating the issue at my end.

Swapygit commented 5 years ago

Hi, My network does not require any work to connect with http/2. can you please replicate the code at your end and let me know what's the issue.

I have sent you the code snippet

Swapygit commented 5 years ago

@AnashOommen Can you help me with this. I have mailed you my coded snippet

AnashOommen commented 5 years ago

Just wanted to update -- I've been hearing similar complaints from other users. Still investigating...

AnashOommen commented 5 years ago

Could you try setting the Timeout setting to 100000? This is in App.config (if you use one), or if you use code to initialize, then

GoogleAdsConfig googleAdsConfig = new GoogleAdsConfig();
googleAdsConfig.Timeout = 100000;
GoogleAdsClient googleAdsClient = new GoogleAdsClient(googleAdsConfig);

The library automatically retries for all variants of StatusCode=Unavailable, and setting the Timeout to a higher value should give more time for the Channel to attempt to recover from error.

Swapygit commented 5 years ago

Hi AnashOommen,

I made changes to the code but I am getting the same error again. Name Resolution Failure or sometimes it throws Transient_Channel_Failure

AnashOommen commented 5 years ago

Name resolution failure definitely translates to a 404.

Swapygit commented 5 years ago

Ok,

Then what could be its resolution

Swapygit commented 5 years ago

Because I tried every possible solution regarding this. I could not get much help from stack overflow. Is there any network issue that needs to be addressed to the Networking department ?

Kindly help.

AnashOommen commented 5 years ago

FWIW, I filed https://github.com/grpc/grpc/issues/18597, since the grpc libraries provide me with little options to help you troubleshoot the error. I apologize for the delay in getting you a workaround.

Swapygit commented 5 years ago

Hi @AnashOommen ,

Just wanted to update you. The same code is running on one of my colleagues machine and I am getting the output. We use the same network connection in office. Is there anything with the machine config.

Swapygit commented 5 years ago

Hi @AnashOommen

I went to the link https://github.com/grpc/grpc/blob/master/doc/environment_variables.md and added the following logging code

Environment.SetEnvironmentVariable("GRPC_TRACE", "api,http,cares_resolver,cares_address_sorting"); Environment.SetEnvironmentVariable("GRPC_VERBOSITY", "debug"); Grpc.Core.GrpcEnvironment.SetLogger(new Grpc.Core.Logging.ConsoleLogger());

And the I was able to get the Campaign data. But after some time again I started getting the exception of "Name Resolution Failure". I found it surprising as the code worked for just some time and again throwing exception.

What might be the reason behind this

Swapygit commented 5 years ago

Hi @AnashOommen ,

I am fetching campaign level data using google ads api. What value of date range should I set so that I can get the "ALL_TIME" campaign data.

Kindly help

AnashOommen commented 5 years ago

For future reference, the issue was with grpc’s dns resolver. Setting the environment variable GRPC_DNS_RESOLVER=native fixes it.

I’ll make this change in the next library version.

AnashOommen commented 5 years ago

Fixed in 2.1.0.