Hello Anash I am trying to download report from google adwords using API. But it gives me error "ReportDefinitionError.CUSTOMER_SERVING_TYPE_REPORT_MISMATCHselector" I am new to google adwords API Please Help Me. For download Report I am using Below code : using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Diagnostics; using System.Net;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } public bool DownloadReportDefinition(string reportDefinitionXml, string authToken, string clientCustomerId, string developerToken, string filePath, bool downloadInMicros) { Uri downloadUrl = new Uri("https://adwords.google.com/api/adwords/reportdownload/v201306"); WebRequest request = HttpWebRequest.Create(downloadUrl); request.Headers.Add("clientCustomerId: " + clientCustomerId); request.Headers.Add("developerToken: " + developerToken); request.Headers.Add("Authorization: GoogleLogin auth=" + authToken); request.Headers.Add("returnMoneyInMicros: " + downloadInMicros.ToString().ToLower()); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) { writer.Write("__rdxml=" + HttpUtility.UrlEncode(reportDefinitionXml)); } WebResponse response = null; bool success = false; try { response = request.GetResponse(); success = true; } catch (WebException ex) { // The server will return an error code other than 200 if something goes wrong. The actual reason for // failure can be found by reading the response. response = ex.Response; } DownloadReportToFile(filePath, response); return success; } private static void DownloadReportToFile(string filePath, WebResponse response) { FileStream outputStream = File.Create(filePath); using (Stream responseStream = response.GetResponseStream()) { CopyStream(responseStream, outputStream); } outputStream.Close(); } private static void CopyStream(Stream sourceStream, Stream targetStream) { int bufferSize = 2 << 20; byte[] buffer = new byte[bufferSize]; int bytesRead = 0; while ((bytesRead = sourceStream.Read(buffer, 0, bufferSize)) != 0) { targetStream.Write(buffer, 0, bytesRead); } } protected void btnDownloadRepot_Click(object sender, EventArgs e) { // string reportDefination = ""; reportDefination = "<reportDefinition>"; reportDefination = reportDefination + "<selector>"; reportDefination = reportDefination + "<fields>Id</fields>"; reportDefination = reportDefination + "<fields>Date</fields>"; reportDefination = reportDefination + "<fields>AdGroupId</fields>"; reportDefination = reportDefination + "<fields>Impressions</fields>"; reportDefination = reportDefination + "<fields>Clicks</fields>"; reportDefination = reportDefination + "<fields>Cost</fields>"; reportDefination = reportDefination + "<fields>Conversions</fields>"; reportDefination = reportDefination + "<fields>ConversionValue</fields>"; reportDefination = reportDefination + "<fields>AveragePosition</fields>"; reportDefination = reportDefination + "<dateRange>"; reportDefination = reportDefination + "<min>20130701</min>"; reportDefination = reportDefination + "<max>20130718</max>"; reportDefination = reportDefination + "</dateRange>"; reportDefination = reportDefination + "</selector>"; reportDefination = reportDefination + "<reportName>AD PERFORMANCE REPORT</reportName>"; reportDefination = reportDefination + "<reportType>AD_PERFORMANCE_REPORT</reportType>"; reportDefination = reportDefination + "<dateRangeType>CUSTOM_DATE</dateRangeType>"; reportDefination = reportDefination + "<downloadFormat>XML</downloadFormat>"; reportDefination = reportDefination + "</reportDefinition>"; string authetoken = ""; authetoken = "xyz"; DownloadReportDefinition(reportDefination, authetoken, "123", "abc", "C:\\Users\\deepak.singh\\Documents", true); } } Thanks & Warm Regards Deepak Singh -- -- =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ Also find us on our blog and discussion group: http://adwordsapi.blogspot.com http://groups.google.com/group/adwords-api =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ You received this message because you are subscribed to the Google Groups "AdWords 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 "AdWords API Forum" group. To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.