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

              // Create the selector.
              Selector selector = new Selector();
              selector.fields = new string[] {"Id", "Name", "Status"};

              // Set the selector paging.
              selector.paging = new Paging();

              int offset = 0;
              int pageSize = 500;

              CampaignPage page = new CampaignPage();

              try {
            do {
              selector.paging.startIndex = offset;
              selector.paging.numberResults = pageSize;

              // Get the campaigns.
              page = campaignService.get(selector);

              // Display the results.
              if (page != null && page.entries != null) {
            int i = offset;
            foreach (Campaign campaign in page.entries) {
              Console.WriteLine("{0}) Campaign with id = '{1}', name = '{2}' and status = '{3}'" +
                " was found.", i + 1, campaign.id, campaign.name, campaign.status);
              i++;
            }
              }
              offset += pageSize;
            } while (offset < page.totalNumEntries);
            Console.WriteLine("Number of campaigns found: {0}", page.totalNumEntries);
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to retrieve campaigns", e);
              }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            // Get the CampaignService.
              CampaignService campaignService =
              (CampaignService) user.GetService(AdWordsService.v201502.CampaignService);

              // Create the selector.
              Selector selector = new Selector() {
            fields = new string[] {
              Campaign.Fields.Id, Campaign.Fields.Name, Campaign.Fields.Status
            },
            paging = Paging.Default
              };

              CampaignPage page = new CampaignPage();

              try {
            do {
              // Get the campaigns.
              page = campaignService.get(selector);

              // Display the results.
              if (page != null && page.entries != null) {
            int i = selector.paging.startIndex;
            foreach (Campaign campaign in page.entries) {
              Console.WriteLine("{0}) Campaign with id = '{1}', name = '{2}' and status = '{3}'" +
                " was found.", i + 1, campaign.id, campaign.name, campaign.status);
              i++;
            }
              }
              selector.paging.IncreaseOffset();
            } while (selector.paging.startIndex < page.totalNumEntries);
            Console.WriteLine("Number of campaigns found: {0}", page.totalNumEntries);
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to retrieve campaigns", e);
              }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            // Get the CampaignService.
              CampaignService campaignService =
              (CampaignService) user.GetService(AdWordsService.v201502.CampaignService);

              // Create the query.
              string query = "SELECT Id, Name, Status ORDER BY Name";

              int offset = 0;
              int pageSize = 500;

              CampaignPage page = new CampaignPage();

              try {
            do {
              string queryWithPaging = string.Format("{0} LIMIT {1}, {2}", query, offset, pageSize);

              // Get the campaigns.
              page = campaignService.query(queryWithPaging);

              // Display the results.
              if (page != null && page.entries != null) {
            int i = offset;
            foreach (Campaign campaign in page.entries) {
              Console.WriteLine("{0}) Campaign with id = '{1}', name = '{2}' and status = '{3}'" +
                " was found.", i + 1, campaign.id, campaign.name, campaign.status);
              i++;
            }
              }
              offset += pageSize;
            } while (offset < page.totalNumEntries);
            Console.WriteLine("Number of campaigns found: {0}", page.totalNumEntries);
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to retrieve campaigns", e);
              }
        }
    /// <summary>
    /// The main method.
    /// </summary>
    /// <param name="args">Command line arguments.</param>
    static void Main(string[] args) {
      AdWordsUser user = new AdWordsUser();

      // This code example shows how to run an AdWords API web application
      // while incorporating the OAuth2 installed application flow into your
      // application. If your application uses a single MCC login to make calls
      // to all your accounts, you shouldn't use this code example. Instead, you
      // should run OAuthTokenGenerator.exe to generate a refresh
      // token and use that configuration in your application's App.config.
      AdWordsAppConfig config = user.Config as AdWordsAppConfig;
      if (user.Config.OAuth2Mode == OAuth2Flow.APPLICATION &&
            string.IsNullOrEmpty(config.OAuth2RefreshToken)) {
         DoAuth2Authorization(user);
      }

      Console.Write("Enter the customer id: ");
      string customerId = Console.ReadLine();
      config.ClientCustomerId = customerId;

      // Get the CampaignService.
      CampaignService campaignService =
          (CampaignService) user.GetService(AdWordsService.v201502.CampaignService);

      // Create the selector.
      Selector selector = new Selector();
      selector.fields = new string[] {"Id", "Name", "Status"};

      // Set the selector paging.
      selector.paging = new Paging();

      int offset = 0;
      int pageSize = 500;

      CampaignPage page = new CampaignPage();

      try {
        do {
          selector.paging.startIndex = offset;
          selector.paging.numberResults = pageSize;

          // Get the campaigns.
          page = campaignService.get(selector);

          // Display the results.
          if (page != null && page.entries != null) {
            int i = offset;
            foreach (Campaign campaign in page.entries) {
              Console.WriteLine("{0}) Campaign with id = '{1}', name = '{2}' and status = '{3}'" +
                " was found.", i + 1, campaign.id, campaign.name, campaign.status);
              i++;
            }
          }
          offset += pageSize;
        } while (offset < page.totalNumEntries);
        Console.WriteLine("Number of campaigns found: {0}", page.totalNumEntries);
      } catch (Exception ex) {
        throw new System.ApplicationException("Failed to retrieve campaigns", ex);
      }
    }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="labelName">ID of the label.</param>
        public void Run(AdWordsUser user, long labelId)
        {
            // Get the CampaignService.
              CampaignService campaignService =
              (CampaignService) user.GetService(AdWordsService.v201502.CampaignService);

              // Create the selector.
              Selector selector = new Selector() {
            fields = new string[] {
              Campaign.Fields.Id, Campaign.Fields.Name, Campaign.Fields.Labels
            },
            predicates = new Predicate[] {
              // Labels filtering is performed by ID. You can use CONTAINS_ANY to
              // select campaigns with any of the label IDs, CONTAINS_ALL to select
              // campaigns with all of the label IDs, or CONTAINS_NONE to select
              // campaigns with none of the label IDs.
              Predicate.ContainsAny(Campaign.Fields.Labels, new string[] { labelId.ToString() })
            },
            paging = Paging.Default
              };

              CampaignPage page = new CampaignPage();

              try {
            do {
              // Get the campaigns.
              page = campaignService.get(selector);

              // Display the results.
              if (page != null && page.entries != null) {
            int i = selector.paging.startIndex;
            foreach (Campaign campaign in page.entries) {
              List<string> labelNames = new List<string>();
              foreach (Label label in campaign.labels) {
                labelNames.Add(label.name);
              }

              Console.WriteLine("{0}) Campaign with id = '{1}', name = '{2}' and labels = '{3}'" +
                  " was found.", i + 1, campaign.id, campaign.name,
                  string.Join(", ", labelNames.ToArray()));
              i++;
            }
              }
              selector.paging.IncreaseOffset();
            } while (selector.paging.startIndex < page.totalNumEntries);
            Console.WriteLine("Number of campaigns found: {0}", page.totalNumEntries);
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to retrieve campaigns by label", e);
              }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="labelName">ID of the label.</param>
        public void Run(AdWordsUser user, long labelId)
        {
            // Get the CampaignService.
              CampaignService campaignService =
              (CampaignService) user.GetService(AdWordsService.v201502.CampaignService);

              // Create the selector.
              Selector selector = new Selector();
              selector.fields = new string[] { "Id", "Name", "Labels" };

              // Labels filtering is performed by ID. You can use CONTAINS_ANY to
              // select campaigns with any of the label IDs, CONTAINS_ALL to select
              // campaigns with all of the label IDs, or CONTAINS_NONE to select
              // campaigns with none of the label IDs.
              Predicate predicate = new Predicate();
              predicate.@operator = PredicateOperator.CONTAINS_ANY;
              predicate.field = "Labels";
              predicate.values = new string[] { labelId.ToString() };
              selector.predicates = new Predicate[] { predicate };

              // Set the selector paging.
              selector.paging = new Paging();

              int offset = 0;
              int pageSize = 500;

              CampaignPage page = new CampaignPage();

              try {
            do {
              selector.paging.startIndex = offset;
              selector.paging.numberResults = pageSize;

              // Get the campaigns.
              page = campaignService.get(selector);

              // Display the results.
              if (page != null && page.entries != null) {
            int i = offset;
            foreach (Campaign campaign in page.entries) {
              List<string> labelNames = new List<string>();
              foreach (Label label in campaign.labels) {
                labelNames.Add(label.name);
              }

              Console.WriteLine("{0}) Campaign with id = '{1}', name = '{2}' and labels = '{3}'" +
                  " was found.", i + 1, campaign.id, campaign.name,
                  string.Join(", ", labelNames.ToArray()));
              i++;
            }
              }
              offset += pageSize;
            } while (offset < page.totalNumEntries);
            Console.WriteLine("Number of campaigns found: {0}", page.totalNumEntries);
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to retrieve campaigns by label", e);
              }
        }