/// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    public void Run(AdWordsUser user) {
      // Get the VideoCampaignService.
      VideoCampaignService videoCampaignService = (VideoCampaignService) user.GetService(
          AdWordsService.v201406.VideoCampaignService);

      int offset = 0;

      VideoCampaignPage page = new VideoCampaignPage();

      try {
        // Create selector.
        VideoCampaignSelector selector = new VideoCampaignSelector();

        selector.paging = new Paging();

        do {
          selector.paging.startIndex = offset;
          selector.paging.numberResults = PAGE_SIZE;

          page = videoCampaignService.get(selector);

          // Display the results.
          if (page != null && page.entries != null) {
            int i = offset;
            foreach (VideoCampaign videoCampaign in page.entries) {
              Console.WriteLine("{0}) Campaign ID {1}, name '{2}' and status '{3}'",
                  (i + 1), videoCampaign.id, videoCampaign.name, videoCampaign.status);
              i++;
            }
          } else {
            Console.WriteLine("No campaigns were found.");
          }
          offset += PAGE_SIZE;
        } while (offset < page.totalNumEntries);
        Console.WriteLine("Number of campaigns found: {0}", page.totalNumEntries);
      } catch (Exception ex) {
        throw new System.ApplicationException("Failed to get campaigns.", ex);
      }
    }
Пример #2
0
 public virtual VideoCampaignPage get(VideoCampaignSelector selector) {
   object[] results = this.Invoke("get", new object[] { selector });
   return ((VideoCampaignPage) (results[0]));
 }
    /// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <param name="campaignId">The campaign ID.</param>
    public void Run(AdWordsUser user, long campaignId) {
      // Get the VideoCampaignService.
      VideoCampaignService videoCampaignService = (VideoCampaignService) user.GetService(
          AdWordsService.v201406.VideoCampaignService);

      // The dates will be interpreted using the account's timezone.
      String minDateTime = DateTime.Now.Year.ToString() + "0101";
      String maxDateTime = DateTime.Now.ToString("yyyyMMdd");

      // Create selector.
      StatsSelector statsSelector = new StatsSelector();
      DateRange dateRange = new DateRange();
      dateRange.min = minDateTime;
      dateRange.max = maxDateTime;

      statsSelector.dateRange = dateRange;
      statsSelector.segmentationDimensions = new SegmentationDimension[] {
          SegmentationDimension.DATE_MONTH };
      statsSelector.metrics = new Metric[] { Metric.VIEWS, Metric.COST, Metric.AVERAGE_CPV };
      statsSelector.summaryTypes = new VideoEntityStatsSummaryType[] {
          VideoEntityStatsSummaryType.ALL };
      statsSelector.segmentedSummaryType = VideoEntityStatsSummaryType.ALL;

      try {
        // Create selector.
        VideoCampaignSelector selector = new VideoCampaignSelector();
        selector.statsSelector = statsSelector;
        selector.ids = new long[] { campaignId };

        selector.paging = new Paging();

        VideoCampaignPage page = videoCampaignService.get(selector);

        if (page != null) {
          if (page.entries != null && page.entries.Length > 0) {
            VideoCampaign videoCampaign = page.entries[0];

            Console.WriteLine("Campaign ID {0}, name '{1}' and status '{2}'", videoCampaign.id,
                videoCampaign.name, videoCampaign.status);
            if (videoCampaign.stats != null) {
              Console.WriteLine("\tCampaign stats:");
              Console.WriteLine("\t\t" + FormatStats(videoCampaign.stats));
            }
            if (videoCampaign.segmentedStats != null) {
              foreach (VideoEntityStats segment in videoCampaign.segmentedStats) {
                Console.WriteLine("\tCampaign segmented stats for month of " +
                    ((DateKey) segment.segmentKey.Item).date);
                Console.WriteLine("\t\t" + FormatStats(segment));
              }
            }
          } else {
            Console.WriteLine("No campaigns were found.");
          }
          if (page.summaryStats != null) {
            foreach (VideoEntityStats summary in page.summaryStats) {
              Console.WriteLine("\tSummary of type " + summary.summaryType);
              Console.WriteLine("\t\t" + FormatStats(summary));
            }
          } else {
            Console.WriteLine("No summary stats found.");
          }
        } else {
          Console.WriteLine("No campaigns were found.");
        }
      } catch (Exception ex) {
        throw new System.ApplicationException("Failed to get campaigns.", ex);
      }
    }