/// <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, "v201506", 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); } }
/// <summary> /// Handles the Click event of the btnDownloadReport control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing /// the event data.</param> protected void OnDownloadReportButtonClick(object sender, EventArgs e) { ConfigureUserForOAuth(); 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", "CriteriaDestinationUrl", "Clicks", "Impressions", "Cost"}; Predicate predicate = new Predicate(); predicate.field = "Status"; predicate.@operator = PredicateOperator.IN; predicate.values = new string[] {"ACTIVE", "PAUSED"}; selector.predicates = new Predicate[] {predicate}; definition.selector = selector; // Optional: Include zero impression rows. AdWordsAppConfig config = (AdWordsAppConfig) user.Config; config.IncludeZeroImpressions = true; string filePath = Path.GetTempFileName(); try { ReportUtilities utilities = new ReportUtilities(user, "v201506", definition); using (ReportResponse response = utilities.GetResponse()) { response.Save(filePath); } } catch (Exception ex) { throw new System.ApplicationException("Failed to download report.", ex); } Response.AddHeader("content-disposition", "attachment;filename=report.gzip"); Response.WriteFile(filePath); Response.End(); }
/// <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; // Optional: Include zero impression rows. AdWordsAppConfig config = (AdWordsAppConfig) user.Config; config.IncludeZeroImpressions = true; string filePath = ExampleUtilities.GetHomeDir() + Path.DirectorySeparatorChar + fileName; try { ReportUtilities utilities = new ReportUtilities(user, "v201506", 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); } }