/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="fileName">The file to which the report is downloaded. /// </param> public void Run(AdWordsUser user, string fileName) { ReportDefinition definition = new ReportDefinition(); definition.reportName = "Last 7 days CRITERIA_PERFORMANCE_REPORT"; definition.reportType = ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT; definition.downloadFormat = DownloadFormat.GZIPPED_CSV; definition.dateRangeType = ReportDefinitionDateRangeType.LAST_7_DAYS; // Create selector. Selector selector = new Selector(); selector.fields = new string[] {"CampaignId", "AdGroupId", "Id", "CriteriaType", "Criteria", "FinalUrls", "Clicks", "Impressions", "Cost"}; Predicate predicate = new Predicate(); predicate.field = "Status"; predicate.@operator = PredicateOperator.IN; predicate.values = new string[] {"ENABLED", "PAUSED"}; selector.predicates = new Predicate[] {predicate}; definition.selector = selector; definition.includeZeroImpressions = true; string filePath = ExampleUtilities.GetHomeDir() + Path.DirectorySeparatorChar + fileName; try { ReportUtilities utilities = new ReportUtilities(user, "v201502", definition); using (ReportResponse response = utilities.GetResponse()) { response.Save(filePath); } Console.WriteLine("Report was downloaded to '{0}'.", filePath); } catch (Exception ex) { throw new System.ApplicationException("Failed to download report.", ex); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="fileName">The file to which the report is downloaded. /// </param> public void Run(AdWordsUser user, string fileName) { ReportDefinition definition = new ReportDefinition() { reportName = "Last 7 days CRITERIA_PERFORMANCE_REPORT", reportType = ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT, downloadFormat = DownloadFormat.GZIPPED_CSV, dateRangeType = ReportDefinitionDateRangeType.LAST_7_DAYS, selector = new Selector() { fields = new string[] {"CampaignId", "AdGroupId", "Id", "CriteriaType", "Criteria", "FinalUrls", "Clicks", "Impressions", "Cost"}, predicates = new Predicate[] { Predicate.In("Status", new string[] {"ENABLED", "PAUSED"}) } }, // Optional: Include zero impression rows. includeZeroImpressions = true }; string filePath = ExampleUtilities.GetHomeDir() + Path.DirectorySeparatorChar + fileName; try { ReportUtilities utilities = new ReportUtilities(user, "v201502", definition); using (ReportResponse response = utilities.GetResponse()) { response.Save(filePath); } Console.WriteLine("Report was downloaded to '{0}'.", filePath); } catch (Exception e) { throw new System.ApplicationException("Failed to download report.", e); } }