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

              // Create a selector.
              Selector selector = new Selector() {
            fields = new string[] {
              Criterion.Fields.Id, AdGroupCriterion.Fields.AdGroupId, Placement.Fields.PlacementUrl
            },
            predicates = new Predicate[] {
              // Select only placements.
              Predicate.Equals(Criterion.Fields.CriteriaType, "PLACEMENT")
            },
            paging = Paging.Default
              };

              AdGroupCriterionPage page = new AdGroupCriterionPage();

              try {
            do {
              // Get the keywords.
              page = adGroupCriterionService.get(selector);

              // Display the results.
              if (page != null && page.entries != null) {
            int i = selector.paging.startIndex;

            foreach (AdGroupCriterion adGroupCriterion in page.entries) {
              bool isNegative = (adGroupCriterion is NegativeAdGroupCriterion);

              // If you are retrieving multiple type of criteria, then you may
              // need to check for
              //
              // if (adGroupCriterion is Placement) { ... }
              //
              // to identify the criterion type.
              Placement placement = (Placement) adGroupCriterion.criterion;
              if (isNegative) {
                Console.WriteLine("{0}) Negative placement with ad group ID = '{1}', placement " +
                    "ID = '{2}', and url = '{3}' was found.", i + 1, adGroupCriterion.adGroupId,
                    placement.id, placement.url);
              } else {
                Console.WriteLine("{0}) Placement with ad group ID = '{1}', placement ID = " +
                    "'{2}' and url = '{3}' was found.", i + 1, adGroupCriterion.adGroupId,
                    placement.id, placement.url);
              }
              i++;
            }
              }
              selector.paging.IncreaseOffset();
            } while (selector.paging.startIndex < page.totalNumEntries);
            Console.WriteLine("Number of placements found: {0}", page.totalNumEntries);
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to retrieve placements.", e);
              }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">ID of the ad group from which keywords are
        /// retrieved.</param>
        public void Run(AdWordsUser user, long adGroupId)
        {
            // Get the AdGroupCriterionService.
              AdGroupCriterionService adGroupCriterionService =
              (AdGroupCriterionService) user.GetService(
              AdWordsService.v201502.AdGroupCriterionService);

              // Create a selector.
              Selector selector = new Selector();
              selector.fields = new string[] { "Id", "KeywordMatchType", "KeywordText", "CriteriaType" };

              // Select only keywords.
              Predicate criteriaPredicate = new Predicate();
              criteriaPredicate.field = "CriteriaType";
              criteriaPredicate.@operator = PredicateOperator.IN;
              criteriaPredicate.values = new string[] {"KEYWORD"};

              // Restrict search to an ad group.
              Predicate adGroupPredicate = new Predicate();
              adGroupPredicate.field = "AdGroupId";
              adGroupPredicate.@operator = PredicateOperator.EQUALS;
              adGroupPredicate.values = new string[] { adGroupId.ToString() };

              selector.predicates = new Predicate[] {adGroupPredicate, criteriaPredicate};

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

              int offset = 0;
              int pageSize = 500;

              AdGroupCriterionPage page = new AdGroupCriterionPage();

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

              // Get the keywords.
              page = adGroupCriterionService.get(selector);

              // Display the results.
              if (page != null && page.entries != null) {
            int i = offset;

            foreach (AdGroupCriterion adGroupCriterion in page.entries) {
              bool isNegative = (adGroupCriterion is NegativeAdGroupCriterion);

              // If you are retrieving multiple type of criteria, then you may
              // need to check for
              //
              // if (adGroupCriterion is Keyword) { ... }
              //
              // to identify the criterion type.
              Keyword keyword = (Keyword) adGroupCriterion.criterion;
              string keywordType = isNegative ? "Negative keyword" : "Keyword";

              Console.WriteLine("{0}) {1} with text = '{2}', matchtype = '{3}', ID = '{4}' and " +
                  "criteria type = '{5}' was found.", i + 1, keywordType, keyword.text,
                  keyword.matchType, keyword.id, keyword.CriterionType);
              i++;
            }
              }
              offset += pageSize;
            } while (offset < page.totalNumEntries);
            Console.WriteLine("Number of keywords found: {0}", page.totalNumEntries);
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to retrieve keywords.", e);
              }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">ID of the ad group from which keywords are
        /// retrieved.</param>
        public void Run(AdWordsUser user, long adGroupId)
        {
            // Get the AdGroupCriterionService.
              AdGroupCriterionService adGroupCriterionService =
              (AdGroupCriterionService) user.GetService(
              AdWordsService.v201502.AdGroupCriterionService);

              // Create a selector.
              Selector selector = new Selector() {
            fields = new string[] {
              Keyword.Fields.Id, Keyword.Fields.KeywordMatchType,
              Keyword.Fields.KeywordText, Keyword.Fields.CriteriaType
            },
            predicates = new Predicate[] {
              // Select only keywords.
              Predicate.In(Keyword.Fields.CriteriaType, new string[] {"KEYWORD"}),

              // Restrict search to an ad group.
              Predicate.Equals(AdGroupCriterion.Fields.AdGroupId, adGroupId),
            },
            paging = Paging.Default
              };

              AdGroupCriterionPage page = new AdGroupCriterionPage();

              try {
            do {
              // Get the keywords.
              page = adGroupCriterionService.get(selector);

              // Display the results.
              if (page != null && page.entries != null) {
            int i = selector.paging.startIndex;

            foreach (AdGroupCriterion adGroupCriterion in page.entries) {
              bool isNegative = (adGroupCriterion is NegativeAdGroupCriterion);

              // If you are retrieving multiple type of criteria, then you may
              // need to check for
              //
              // if (adGroupCriterion is Keyword) { ... }
              //
              // to identify the criterion type.
              Keyword keyword = (Keyword) adGroupCriterion.criterion;
              string keywordType = isNegative ? "Negative keyword" : "Keyword";

              Console.WriteLine("{0}) {1} with text = '{2}', matchtype = '{3}', ID = '{4}' and " +
                  "criteria type = '{5}' was found.", i + 1, keywordType, keyword.text,
                  keyword.matchType, keyword.id, keyword.CriterionType);
              i++;
            }
              }
              selector.paging.IncreaseOffset();
            } while (selector.paging.startIndex < page.totalNumEntries);
            Console.WriteLine("Number of keywords found: {0}", page.totalNumEntries);
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to retrieve keywords.", e);
              }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            // Get the AdGroupCriterionService.
              AdGroupCriterionService adGroupCriterionService =
              (AdGroupCriterionService) user.GetService(
              AdWordsService.v201502.AdGroupCriterionService);

              // Create a selector.
              Selector selector = new Selector();
              selector.fields = new string[] {"Id", "AdGroupId", "PlacementUrl"};

              // Select only keywords.
              Predicate predicate = new Predicate();
              predicate.field = "CriteriaType";
              predicate.@operator = PredicateOperator.EQUALS;
              predicate.values = new string[] {"PLACEMENT"};
              selector.predicates = new Predicate[] {predicate};

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

              int offset = 0;
              int pageSize = 500;

              AdGroupCriterionPage page = new AdGroupCriterionPage();

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

              // Get the keywords.
              page = adGroupCriterionService.get(selector);

              // Display the results.
              if (page != null && page.entries != null) {
            int i = offset;

            foreach (AdGroupCriterion adGroupCriterion in page.entries) {
              bool isNegative = (adGroupCriterion is NegativeAdGroupCriterion);

              // If you are retrieving multiple type of criteria, then you may
              // need to check for
              //
              // if (adGroupCriterion is Placement) { ... }
              //
              // to identify the criterion type.
              Placement placement = (Placement) adGroupCriterion.criterion;
              if (isNegative) {
                Console.WriteLine("{0}) Negative placement with ad group ID = '{1}', placement " +
                    "ID = '{2}', and url = '{3}' was found.", i, adGroupCriterion.adGroupId,
                    placement.id, placement.url);
              } else {
                Console.WriteLine("{0}) Placement with ad group ID = '{1}', placement ID = '{2}' " +
                    "and url = '{3}' was found.", i, adGroupCriterion.adGroupId,
                    placement.id, placement.url);
              }
              i++;
            }
              }
              offset += pageSize;
            } while (offset < page.totalNumEntries);
            Console.WriteLine("Number of placements found: {0}", page.totalNumEntries);
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to retrieve placements.", e);
              }
        }