How to Get Campaign Data in C# Grid

356 views
Skip to first unread message

Pravin Yadav

unread,
Apr 1, 2015, 2:08:27 AM4/1/15
to adwor...@googlegroups.com
Hi

I am using Google.Api.Ads.AdWords.v201406 with dot.net code and getting campaign using CampaignService. 
But I am getting error.  "Failed to get campaigns. Exception says "The request failed with HTTP status 404: Not Found."". Please see in line of  code for error with Red mark.

Is there any changes to AdWords API? Please let me know and give me DLL for updated version or link to download it.

Here is code :

 Selector selector = new Selector();
            selector.fields = new string[] { "Id", "Name", "Status" };

            OrderBy orderByName = new OrderBy();
            orderByName.field = "Name";
            orderByName.sortOrder = SortOrder.ASCENDING;

            selector.ordering = new OrderBy[] { orderByName };
            (user.Config as AdWordsAppConfig).ClientCustomerId = txtCustomerId.Text;

            try
            {
                CampaignService service = (CampaignService)user.GetService(AdWordsService.v201406.CampaignService);
                 
                CampaignPage page = service.get(selector);

                // Display campaigns.
                if (page != null && page.entries != null && page.entries.Length > 0)
                {
                    DataTable dataTable = new DataTable();
                    dataTable.Columns.AddRange(new DataColumn[] 
                     {
                       new DataColumn("Serial No.", typeof(int)),
                       new DataColumn("Campaign Id", typeof(long)),
                       new DataColumn("Campaign Name", typeof(string)),
                       new DataColumn("Status", typeof(string))
                    });
                    for (int i = 0; i < page.entries.Length; i++)
                    {
                        Campaign campaign = page.entries[i];
                        DataRow dataRow = dataTable.NewRow();
                        dataRow.ItemArray = new object[] { i + 1, campaign.id, campaign.name, campaign.status.ToString() };
                        dataTable.Rows.Add(dataRow);
                    }
                    CampaignGrid.DataSource = dataTable;
                    CampaignGrid.DataBind();
                }
                else
                {
                    Response.Write("No campaigns were found.");
                } 

Josh Radcliff (AdWords API Team)

unread,
Apr 1, 2015, 2:50:21 PM4/1/15
to adwor...@googlegroups.com
Hi,

Is it just calls against CampaignService that are failing, or do calls against all services fail?

One thing to check would be to try to hit the WSDL endpoint from the host where you are running the example, e.g., confirm that you can download the WSDL at https://adwords.google.com/api/adwords/cm/v201406/CampaignService?wsdl using curl or wget.

Thanks,
Josh, AdWords API Team

Pravin Yadav

unread,
Apr 3, 2015, 9:05:08 AM4/3/15
to adwor...@googlegroups.com


On Thursday, April 2, 2015 at 12:20:21 AM UTC+5:30, Josh Radcliff (AdWords API Team) wrote:
Hi,

Is it just calls against CampaignService that are failing, or do calls against all services fail?

One thing to check would be to try to hit the WSDL endpoint from the host where you are running the example, e.g., confirm that you can download the WSDL at https://adwords.google.com/api/adwords/cm/v201406/CampaignService?wsdl using curl or wget.

Thanks,
Josh, AdWords API Team


Hi,
     
       i implement application as per your above solution but i got below error 
...pls give me solution as early as possible...
Failed to get campaigns. Exception says "An API exception has occurred. See ApiException and InnerException fields for more details.
" Inner Exception is System.Web.Services.Protocols.SoapException: [QuotaCheckError.INVALID_TOKEN_HEADER @ ; trigger:'932894988843-7oshj76q6...@developer.gserviceaccount.com'] at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at Google.Api.Ads.Common.Lib.AdsSoapClient.MakeApiCall(String methodName, Object[] parameters) 

Josh Radcliff (AdWords API Team)

unread,
Apr 3, 2015, 9:49:00 AM4/3/15
to adwor...@googlegroups.com
Hi,

It sounds like you may not have set up your config properly. Have you read through our wiki on App.config? In particular, I'd recommend the section on OAuth2 configuration values, since that error suggests that your OAuth2 values are not set up properly.
Message has been deleted

Josh Radcliff (AdWords API Team)

unread,
Apr 8, 2015, 11:07:20 AM4/8/15
to adwor...@googlegroups.com
Hi,

Please go through our sign up guide for instructions on requesting a developer token.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages