/// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign for which disapproved ads
        /// are retrieved.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the AdGroupAdService.
              AdGroupAdService service =
              (AdGroupAdService) user.GetService(AdWordsService.v201306.AdGroupAdService);

              // Get all the disapproved ads for this campaign.
              string query = string.Format("SELECT Id, DisapprovalReasons WHERE CampaignId = {0} AND " +
              "AdGroupCreativeApprovalStatus = DISAPPROVED ORDER BY Id", campaignId);

              int offset = 0;
              int pageSize = 500;

              AdGroupAdPage page = new AdGroupAdPage();

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

              // Get the disapproved ads.
              page = service.query(queryWithPaging);

              // Display the results.
              if (page != null && page.entries != null) {
            int i = offset;
            foreach (AdGroupAd adGroupAd in page.entries) {
              Console.WriteLine("{0}) Ad id {1} has been disapproved for the following " +
                  "reason(s):", i, adGroupAd.ad.id);
              foreach (string reason in adGroupAd.ad.disapprovalReasons) {
                Console.WriteLine("    {0}", reason);
              }
              i++;
            }
              }
              offset += pageSize;
            } while (offset < page.totalNumEntries);
            Console.WriteLine("Number of disapproved ads found: {0}", page.totalNumEntries);
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to get disapproved ads.", ex);
              }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">Id of the ad group from which text ads are
        /// retrieved.</param>
        public void Run(AdWordsUser user, long adGroupId)
        {
            // Get the AdGroupAdService.
              AdGroupAdService service =
              (AdGroupAdService) user.GetService(AdWordsService.v201306.AdGroupAdService);

              // Create a selector.
              Selector selector = new Selector();
              selector.fields = new string[] {"Id", "Status", "Headline", "Description1", "Description2",
              "DisplayUrl"};

              // Set the sort order.
              OrderBy orderBy = new OrderBy();
              orderBy.field = "Id";
              orderBy.sortOrder = SortOrder.ASCENDING;
              selector.ordering = new OrderBy[] {orderBy};

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

              // Retrieve only text ads.
              Predicate typePredicate = new Predicate();
              typePredicate.field = "AdType";
              typePredicate.@operator = PredicateOperator.EQUALS;
              typePredicate.values = new string[] {"TEXT_AD"};

              // By default disabled ads aren't returned by the selector. To return
              // them include the DISABLED status in the statuses field.
              Predicate statusPredicate = new Predicate();
              statusPredicate.field = "Status";
              statusPredicate.@operator = PredicateOperator.IN;

              statusPredicate.values = new string[] {AdGroupAdStatus.ENABLED.ToString(),
              AdGroupAdStatus.PAUSED.ToString(), AdGroupAdStatus.DISABLED.ToString()};

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

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

              int offset = 0;
              int pageSize = 500;

              AdGroupAdPage page = new AdGroupAdPage();

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

              // Get the text ads.
              page = service.get(selector);

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

            foreach (AdGroupAd adGroupAd in page.entries) {
              TextAd textAd = (TextAd) adGroupAd.ad;
              Console.WriteLine("{0}) Ad id is {1} and status is {2}", i + 1, textAd.id,
                  adGroupAd.status);
              Console.WriteLine("  {0}\n  {1}\n  {2}\n  {3}", textAd.headline,
                  textAd.description1, textAd.description2, textAd.displayUrl);
              i++;
            }
              }
              offset += pageSize;
            } while (offset < page.totalNumEntries);
            Console.WriteLine("Number of text ads found: {0}", page.totalNumEntries);
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to get text ads", ex);
              }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign for which disapproved ads
        /// are retrieved.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the AdGroupAdService.
              AdGroupAdService service =
              (AdGroupAdService) user.GetService(AdWordsService.v201306.AdGroupAdService);

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

              // Create the filter.
              Predicate campaignPredicate = new Predicate();
              campaignPredicate.@operator = PredicateOperator.EQUALS;
              campaignPredicate.field = "CampaignId";
              campaignPredicate.values = new string[] {campaignId.ToString()};

              Predicate approvalPredicate = new Predicate();
              approvalPredicate.@operator = PredicateOperator.EQUALS;
              approvalPredicate.field = "AdGroupCreativeApprovalStatus";
              approvalPredicate.values = new string[] {AdGroupAdApprovalStatus.DISAPPROVED.ToString()};

              selector.predicates = new Predicate[] {campaignPredicate, approvalPredicate};

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

              int offset = 0;
              int pageSize = 500;

              AdGroupAdPage page = new AdGroupAdPage();

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

              // Get the disapproved ads.
              page = service.get(selector);

              // Display the results.
              if (page != null && page.entries != null) {
            int i = offset;
            foreach (AdGroupAd adGroupAd in page.entries) {
              Console.WriteLine("{0}) Ad id {1} has been disapproved for the following " +
                  "reason(s):", i, adGroupAd.ad.id);
              foreach (string reason in adGroupAd.ad.disapprovalReasons) {
                Console.WriteLine("    {0}", reason);
              }
              i++;
            }
              }
              offset += pageSize;
            } while (offset < page.totalNumEntries);
            Console.WriteLine("Number of disapproved ads found: {0}", page.totalNumEntries);
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to get disapproved ads.", ex);
              }
        }