/// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <param name="adGroupId">Id of the ad group from which third party
    /// redirect ads are retrieved.</param>
    public void Run(AdWordsUser user, long adGroupId) {
      // Get the AdGroupAdService.
      AdGroupAdService service =
          (AdGroupAdService) user.GetService(AdWordsService.v201506.AdGroupAdService);

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

      // 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 third party redirect ads.
      Predicate typePredicate = new Predicate();
      typePredicate.field = "AdType";
      typePredicate.@operator = PredicateOperator.EQUALS;
      typePredicate.values = new string[] {"THIRD_PARTY_REDIRECT_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 third party redirect ads.
          page = service.get(selector);

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

            foreach (AdGroupAd adGroupAd in page.entries) {
              ThirdPartyRedirectAd thirdPartyRedirectAd = (ThirdPartyRedirectAd) adGroupAd.ad;
              Console.WriteLine("{0}) Ad id is {1} and status is {2}", i, thirdPartyRedirectAd.id,
                  adGroupAd.status);
              Console.WriteLine("  Url: {0}\n  Display Url: {1}\n  Snippet:{2}",
                  thirdPartyRedirectAd.finalUrls[0], thirdPartyRedirectAd.displayUrl,
                  thirdPartyRedirectAd.snippet);
              i++;
            }
          }
          offset += pageSize;
        } while (offset < page.totalNumEntries);
        Console.WriteLine("Number of third party redirect ads found: {0}", page.totalNumEntries);
      } catch (Exception ex) {
        throw new System.ApplicationException("Failed to get third party redirect ad(s).", ex);
      }
    }
        /// <summary>
        /// Handles the Click event of the btnGetCampaigns control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="eventArgs">The <see cref="System.EventArgs"/> instance containing
        /// the event data.</param>
        protected void OnGetCampaignsButtonClick(object sender, EventArgs eventArgs)
        {
            ConfigureUserForOAuth();

              // Now proceed to make your API calls as usual.
              // Create a selector.
              Selector selector = new Selector();
              selector.fields = new string[] {"Id", "Name", "Status"};

              OrderBy orderByName = new OrderBy();
              orderByName.field = "Name";
              orderByName.sortOrder = SortOrder.ASCENDING;

              selector.ordering = new OrderBy[] {orderByName};
              (user.Config as AdWordsAppConfig).ClientCustomerId = txtCustomerId.Text;

              try {
            CampaignService service =
            (CampaignService) user.GetService(AdWordsService.v201506.CampaignService);

            CampaignPage page = service.get(selector);

            // Display campaigns.
            if (page != null && page.entries != null && page.entries.Length > 0) {
              DataTable dataTable = new DataTable();
              dataTable.Columns.AddRange(new DataColumn[] {
              new DataColumn("Serial No.", typeof(int)),
              new DataColumn("Campaign Id", typeof(long)),
              new DataColumn("Campaign Name", typeof(string)),
              new DataColumn("Status", typeof(string))
              });
              for (int i = 0; i < page.entries.Length; i++) {
            Campaign campaign = page.entries[i];
            DataRow dataRow = dataTable.NewRow();
            dataRow.ItemArray = new object[] {i + 1, campaign.id, campaign.name,
                campaign.status.ToString()
            };
            dataTable.Rows.Add(dataRow);
              }
              CampaignGrid.DataSource = dataTable;
              CampaignGrid.DataBind();
            } else {
              Response.Write("No campaigns were found.");
            }
              } catch (Exception e) {
            Response.Write(string.Format("Failed to get campaigns. Exception says \"{0}\"",
            e.Message));
              }
        }