Google.Api.Ads.AdWords.Examples.CSharp.v201306.DownloadCriteriaReport.Run C# (CSharp) Méthode

Run() public méthode

Runs the code example.
public Run ( Google.Api.Ads.AdWords.Lib.AdWordsUser user, string fileName ) : void
user Google.Api.Ads.AdWords.Lib.AdWordsUser The AdWords user.
fileName string The file to which the report is downloaded. ///
Résultat void
        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);
              }
        }

Usage Example

 /// <summary>
 /// Main method, to run this code example as a standalone application.
 /// </summary>
 /// <param name="args">The command line arguments.</param>
 public static void Main(string[] args)
 {
     DownloadCriteriaReport codeExample = new DownloadCriteriaReport();
       Console.WriteLine(codeExample.Description);
       try {
     string fileName = "INSERT_FILE_NAME_HERE";
     codeExample.Run(new AdWordsUser(), fileName);
       } catch (Exception ex) {
     Console.WriteLine("An exception occurred while running this code example. {0}",
     ExampleUtilities.FormatException(ex));
       }
 }
DownloadCriteriaReport