Question about C# Example

26 views
Skip to first unread message

KevinW

unread,
Jun 9, 2019, 7:10:40 PM6/9/19
to AdWords API and Google Ads API Forum
this is an update to an earlier question I had posted that was incomplete and i deleted

I'm trying the following code from the C# example library but getting connection errors which I thing is due to the correct parameters not being passed 

1- am I passing the customerId correctly? (the account I am trying to read)?  the long.Parse("123-456-7890") gives an error
(why is this converted to long when it is converted back to a string when it is used in Run?)
2 - Should the 'client' include the AdWordsAPI parameters from the app.config ?  I have the correct data in the app.config but when debugging the config section for client only shows defaults for some fields and empty strings for the developerToken, etc
3 - if this is correct how do I fix it?

        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 = 1327758399;// long.Parse("INSERT_CUSTOMER_ID_HERE");

            codeExample.Run(new GoogleAdsClient(), customerId);
            Console.Read();
        }
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
                        ORDER BY campaign.id",
                CustomerId = customerId.ToString()
            };

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


.


Google Ads API Forum Advisor Prod

unread,
Jun 9, 2019, 10:46:04 PM6/9/19
to adwor...@googlegroups.com
Hi Kevin,

Thanks for reaching out. Your concern appears to be related to the .NET client library. However, I will try to provide insights on your concern.

For your first concern, could you try inserting the customer Id inside the parameter as is? See example below. 

long customerId = long.Parse("1324567890"); //Make sure that all hyphens (-) are removed.

For your second concern, you should fill in your clientId, clientSecret, refreshToken, and your developer token in the App.config file. These credentials are the same with the ones you are using in AdWords API. 

If you have further concerns, you can open your concern to the
.NET GitHub Issue Tracker as the client library owners are better equipped in answering your concerns.

Regards,
Dannison
Google Ads API Team


 

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