/// <summary>
        /// Creates a tree from criteria passed into the factory method.
        /// </summary>
        private void CreateTreeFromCriteria()
        {
            AdGroupCriterionService service = (AdGroupCriterionService)user.GetService(
                AdWordsService.v201806.AdGroupCriterionService);

            string[] REQUIRED_SELECTOR_FIELD_ENUMS = new string[] {
                AdGroupCriterion.Fields.AdGroupId,
                Criterion.Fields.Id,
                ProductPartition.Fields.ParentCriterionId,
                ProductPartition.Fields.PartitionType,
                ProductPartition.Fields.CriteriaType,
                ProductPartition.Fields.CaseValue,
                CpcBid.Fields.CpcBid,
                CpcBid.Fields.CpcBidSource,
                BiddableAdGroupCriterion.Fields.Status
            };

            Selector selector = new Selector()
            {
                fields     = REQUIRED_SELECTOR_FIELD_ENUMS,
                predicates = new Predicate[] {
                    Predicate.Equals(AdGroupCriterion.Fields.AdGroupId, ADGROUP_ID)
                }
            };

            AdGroupCriterionPage retval = service.get(selector);

            tree = ProductPartitionTree.CreateAdGroupTree(ADGROUP_ID,
                                                          new List <AdGroupCriterion>(retval.entries));
        }
        /// <summary>
        /// Downloads the product partition criteria from an ad group.
        /// </summary>
        /// <param name="user">The AdWords user instance that owns the ad group.
        /// </param>
        /// <param name="adGroupId">The ad group ID.</param>
        /// <returns>A list of product partition criteria.</returns>
        private static List <AdGroupCriterion> DownloadCriteria(AdWordsUser user, long adGroupId)
        {
            List <AdGroupCriterion> retval = new List <AdGroupCriterion>();

            // Get the AdGroupCriterionService.
            AdGroupCriterionService adGroupCriterionService = (AdGroupCriterionService)
                                                              user.GetService(AdWordsService.v201509.AdGroupCriterionService);

            Selector selector = new Selector()
            {
                fields     = REQUIRED_SELECTOR_FIELD_ENUMS,
                predicates = new Predicate[] {
                    new Predicate()
                    {
                        field     = "AdGroupId",
                        @operator = PredicateOperator.EQUALS,
                        values    = new string[] { adGroupId.ToString() }
                    },
                    new Predicate()
                    {
                        field     = "CriteriaType",
                        @operator = PredicateOperator.EQUALS,
                        values    = new string[] { "PRODUCT_PARTITION" }
                    },
                    new Predicate()
                    {
                        field     = "Status",
                        @operator = PredicateOperator.IN,
                        values    = new string[] {
                            UserStatus.ENABLED.ToString(),
                     UserStatus.PAUSED.ToString()
                        }
                    },
                },
                paging = new Paging()
                {
                    numberResults = PAGE_SIZE
                }
            };

            AdGroupCriterionPage page;

            do
            {
                // Get the next page of results.
                page = adGroupCriterionService.get(selector);

                if (page != null && page.entries != null)
                {
                    retval.AddRange(page.entries);
                    selector.paging.IncreaseOffset();
                }
            } while (selector.paging.startIndex < page.totalNumEntries);

            return(retval);
        }
Exemple #3
0
        /// <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.v201607.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),
                },
                ordering = new OrderBy[] { OrderBy.Asc(Keyword.Fields.KeywordText) },
                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)
                        {
                            Keyword keyword = (Keyword)adGroupCriterion.criterion;

                            Console.WriteLine("{0}) Keyword with text '{1}', match type '{2}', criteria " +
                                              "type '{3}', and ID {4} was found.", i + 1, keyword.text, keyword.matchType,
                                              keyword.type, keyword.id);
                            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>
        /// <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.v201506.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);
            }
        }
Exemple #5
0
        /// <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.v201506.AdGroupCriterionService);

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

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

            // Select only keywords.
            Predicate predicate = new Predicate();

            predicate.field     = "CriteriaType";
            predicate.@operator = PredicateOperator.EQUALS;
            predicate.values    = new string[] { "KEYWORD" };
            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 Keyword) { ... }
                            //
                            // to identify the criterion type.
                            Keyword keyword = (Keyword)adGroupCriterion.criterion;
                            if (isNegative)
                            {
                                Console.WriteLine("{0}) Negative keyword with ad group ID = '{1}', keyword ID " +
                                                  "= '{2}', and text = '{3}' was found.", i + 1, adGroupCriterion.adGroupId,
                                                  keyword.id, keyword.text);
                            }
                            else
                            {
                                Console.WriteLine("{0}) Keyword with ad group ID = '{1}', keyword ID = '{2}', " +
                                                  "text = '{3}' and matchType = '{4} was found.", i + 1,
                                                  adGroupCriterion.adGroupId, keyword.id, keyword.text, keyword.matchType);
                            }
                            i++;
                        }
                    }
                    offset += pageSize;
                } while (offset < page.totalNumEntries);
                Console.WriteLine("Number of keywords found: {0}", page.totalNumEntries);
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to retrieve keywords.", ex);
            }
        }
Exemple #6
0
        /// <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.v201409.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 ex) {
                throw new System.ApplicationException("Failed to retrieve placements.");
            }
        }
Exemple #7
0
        /// <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 ex) {
                throw new System.ApplicationException("Failed to retrieve keywords.", ex);
            }
        }
Exemple #8
0
        /// <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);
            }
        }
Exemple #9
0
        private void GetAgSettings_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;
            }

            AdGroupCriterionService agCriterionService = (AdGroupCriterionService)User.GetService(AdWordsService.v201302.AdGroupCriterionService);

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

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

            // 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;

            AdGroupCriterionPage page = new AdGroupCriterionPage();

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

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

                    // Display the results.
                    if (page != null && page.entries != null)
                    {
                        int i = offset;
                        foreach (AdGroupCriterion adGroupCriterion 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);
            }
        }