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",
"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;
definition.includeZeroImpressions = true;
string filePath = ExampleUtilities.GetHomeDir() + Path.DirectorySeparatorChar + fileName;
try {
// If you know that your report is small enough to fit in memory, then
// you can instead use
// ReportUtilities utilities = new ReportUtilities(user);
// utilities.ReportVersion = "v201306";
// ClientReport report = utilities.GetClientReport(definition);
//
// // Get the text report directly if you requested a text format
// // (e.g. xml)
// string reportText = report.Text;
//
// // Get the binary report if you requested a binary format
// // (e.g. gzip)
// byte[] reportBytes = report.Contents;
//
// // Deflate a zipped binary report for further processing.
// string deflatedReportText = Encoding.UTF8.GetString(
// MediaUtilities.DeflateGZipData(report.Contents));
ReportUtilities utilities = new ReportUtilities(user);
utilities.ReportVersion = "v201306";
utilities.DownloadClientReport(definition, filePath);
Console.WriteLine("Report was downloaded to '{0}'.", filePath);
} catch (Exception ex) {
throw new System.ApplicationException("Failed to download report.", ex);
}
}