예제 #1
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign for which ad groups are
        /// retrieved.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            using (AdGroupService adGroupService =
                       (AdGroupService)user.GetService(AdWordsService.v201809.AdGroupService))
            {
                // Create the selector.
                Selector selector = new Selector()
                {
                    fields = new string[]
                    {
                        AdGroup.Fields.Id,
                        AdGroup.Fields.Name
                    },
                    predicates = new Predicate[]
                    {
                        Predicate.Equals(AdGroup.Fields.CampaignId, campaignId)
                    },
                    paging   = Paging.Default,
                    ordering = new OrderBy[]
                    {
                        OrderBy.Asc(AdGroup.Fields.Name)
                    }
                };

                AdGroupPage page = new AdGroupPage();

                try
                {
                    do
                    {
                        // Get the ad groups.
                        page = adGroupService.get(selector);

                        // Display the results.
                        if (page != null && page.entries != null)
                        {
                            int i = selector.paging.startIndex;
                            foreach (AdGroup adGroup in page.entries)
                            {
                                Console.WriteLine("{0}) Ad group name is '{1}' and id is {2}.",
                                                  i + 1, adGroup.name, adGroup.id);
                                i++;
                            }
                        }

                        // Note: You can also use selector.paging.IncrementOffsetBy(customPageSize)
                        selector.paging.IncreaseOffset();
                    } while (selector.paging.startIndex < page.totalNumEntries);

                    Console.WriteLine("Number of ad groups found: {0}", page.totalNumEntries);
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException("Failed to retrieve ad groups.", e);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign for which ad groups are
        /// retrieved.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the AdGroupService.
            AdGroupService adGroupService =
                (AdGroupService)user.GetService(AdWordsService.v201409.AdGroupService);

            // Create the selector.
            Selector selector = new Selector();

            selector.fields = new string[] { "Id", "Name" };

            // Create the filters.
            Predicate predicate = new Predicate();

            predicate.field     = "CampaignId";
            predicate.@operator = PredicateOperator.EQUALS;
            predicate.values    = new string[] { campaignId.ToString() };
            selector.predicates = new Predicate[] { predicate };

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

            int offset   = 0;
            int pageSize = 500;

            AdGroupPage page = new AdGroupPage();

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

                    // Get the ad groups.
                    page = adGroupService.get(selector);

                    // Display the results.
                    if (page != null && page.entries != null)
                    {
                        int i = offset;
                        foreach (AdGroup adGroup in page.entries)
                        {
                            Console.WriteLine("{0}) Ad group name is '{1}' and id is {2}.", i + 1, adGroup.name,
                                              adGroup.id);
                            i++;
                        }
                    }
                    offset += pageSize;
                } while (offset < page.totalNumEntries);
                Console.WriteLine("Number of ad groups found: {0}", page.totalNumEntries);
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to retrieve ad groups.", ex);
            }
        }
예제 #3
0
        public static List <AdGroup> GetAdGroups(AdWordsUser user, long campaignId, bool getAllAdGroups)
        {
            using (AdGroupService adGroupService =
                       (AdGroupService)user.GetService(AdWordsService.v201710.AdGroupService))
            {
                // Create the selector.
                Selector selector = new Selector()
                {
                    fields     = new string[] { AdGroup.Fields.Id, AdGroup.Fields.Name, AdGroup.Fields.CampaignId, AdGroup.Fields.Status },
                    predicates = new Predicate[] {
                        Predicate.Equals(AdGroup.Fields.CampaignId, campaignId)
                    },
                    paging   = Paging.Default,
                    ordering = new OrderBy[] { OrderBy.Asc(AdGroup.Fields.Name) }
                };

                AdGroupPage page = new AdGroupPage();

                List <AdGroup> result = new List <AdGroup>();

                try
                {
                    // Get the ad groups.
                    page = adGroupService.get(selector);

                    if (page.entries != null)
                    {
                        foreach (AdGroup item in page.entries)
                        {
                            if (!getAllAdGroups)
                            {
                                if (item.status == AdGroupStatus.PAUSED)
                                {
                                    result.Add(item);
                                }
                            }
                            else
                            {
                                result.Add(item);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException("Failed to retrieve ad groups.", e);
                }
                return(result);
            }
        }
예제 #4
0
        /// <summary>
        /// Gets the ad group for policy checks.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="campaignId">The campaign identifier.</param>
        /// <returns></returns>
        /// <exception cref="System.ApplicationException">Failed to retrieve ad
        /// group for policy checks.</exception>
        private long GetAdGroupForPolicyChecks(AdWordsUser user, long campaignId)
        {
            AdGroupService adGroupService = (AdGroupService)user.GetService(
                AdWordsService.v201607.AdGroupService);

            string query = string.Format("Select AdGroupId where CampaignId = {0}", campaignId);

            try {
                AdGroupPage page = adGroupService.query(query);
                return(page.entries[0].id);
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to retrieve ad group for policy checks.", e);
            }
        }
    /// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <param name="campaignId">Id of the campaign for which ad groups are
    /// retrieved.</param>
    public void Run(AdWordsUser user, long campaignId) {
      // Get the AdGroupService.
      AdGroupService adGroupService =
          (AdGroupService) user.GetService(AdWordsService.v201509.AdGroupService);

      // Create the selector.
      Selector selector = new Selector() {
        fields = new string[] { AdGroup.Fields.Id, AdGroup.Fields.Name },
        predicates = new Predicate[] {
          Predicate.Equals(AdGroup.Fields.CampaignId, campaignId)
        },
        paging = Paging.Default,
        ordering = new OrderBy[] {OrderBy.Asc(AdGroup.Fields.Name)}
      };

      AdGroupPage page = new AdGroupPage();

      try {
        do {
          // Get the ad groups.
          page = adGroupService.get(selector);

          // Display the results.
          if (page != null && page.entries != null) {
            int i = selector.paging.startIndex;
            foreach (AdGroup adGroup in page.entries) {
              Console.WriteLine("{0}) Ad group name is '{1}' and id is {2}.", i + 1, adGroup.name,
                  adGroup.id);
              i++;
            }
          }
          // Note: You can also use selector.paging.IncrementOffsetBy(customPageSize)
          selector.paging.IncreaseOffset();
        } while (selector.paging.startIndex < page.totalNumEntries);
        Console.WriteLine("Number of ad groups found: {0}", page.totalNumEntries);
      } catch (Exception e) {
        throw new System.ApplicationException("Failed to retrieve ad groups.", e);
      }
    }
예제 #6
0
        private void GetAgSettings2_Click(object sender, EventArgs e)
        {
            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "DeveloperToken", this.DeveloperToken.Text },
                { "UserAgent", String.Format("Edge File Manager (version {0})", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()) },
                { "EnableGzipCompression", this.EnableGzipCompression.Text },
                { "ClientCustomerId", this.ClientCustomerId.Text },
                { "Email", this.Email.Text }
            };


            User = new AdWordsUser(headers);

            try
            {
                //Getting AuthToken
                (User.Config as AdWordsAppConfig).AuthToken = AdwordsUtill.GetAuthToken(User);
            }
            catch (Exception exc)
            {
                this.rchtxt.Text = exc.Message + " #### " + exc.InnerException != null ? exc.InnerException.Message : string.Empty;
            }

            AdGroupService      agService = (AdGroupService)User.GetService(AdWordsService.v201302.AdGroupService);
            ConstantDataService constData = (ConstantDataService)User.GetService(AdWordsService.v201302.ConstantDataService);

            Language[] lang = constData.getLanguageCriterion();

            // Create the selector.
            Selector selector = new Selector();

            selector.fields = new string[] { "Id", "Status", "Clicks" };

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

            //  selector.predicates = new Predicate[] { predicate };

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

            int offset   = 0;
            int pageSize = 500;

            AdGroupPage page = new AdGroupPage();

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

                    // Get all campaign targets.
                    page = agService.get(selector);

                    // Display the results.
                    if (page != null && page.entries != null)
                    {
                        int i = offset;
                        foreach (AdGroup adGroup in page.entries)
                        {
                            i++;
                        }
                    }
                    offset += pageSize;
                } while (offset < page.totalNumEntries);
                Console.WriteLine("Number of ad groups criteria found: {0}", page.totalNumEntries);
            }
            catch (Exception ex)
            {
                throw new System.ApplicationException("Failed to get adgroup targeting criteria.", ex);
            }
        }