Пример #1
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign from which targeting
        /// criteria are retrieved.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the CampaignCriterionService.
            CampaignCriterionService campaignCriterionService =
                (CampaignCriterionService)user.GetService(
                    AdWordsService.v201406.CampaignCriterionService);

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

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

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

            CampaignCriterionPage page = new CampaignCriterionPage();

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

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

                    // Display the results.
                    if (page != null && page.entries != null)
                    {
                        int i = offset;
                        foreach (CampaignCriterion campaignCriterion in page.entries)
                        {
                            string negative = (campaignCriterion is NegativeCampaignCriterion) ? "Negative " : "";
                            Console.WriteLine("{0}) {1}Campaign criterion with id = '{2}' and Type = {3} was " +
                                              " found for campaign id '{4}'", i, negative, campaignCriterion.criterion.id,
                                              campaignCriterion.criterion.type, campaignCriterion.campaignId);
                            i++;
                        }
                    }
                    offset += pageSize;
                } while (offset < page.totalNumEntries);
                Console.WriteLine("Number of campaign targeting criteria found: {0}", page.totalNumEntries);
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to get campaign targeting criteria.", ex);
            }
        }
Пример #2
0
        public List <GeoTarget> GetCampaignGeoTargets(string campaignId)
        {
            CampaignCriterionService campaignCriterionService = (CampaignCriterionService)_adwordsUser.GetService(AdWordsService.v201708.CampaignCriterionService);

            Selector selector = new Selector();

            selector.fields = new string[] { "CampaignId", "Id", "CriteriaType", "LocationName" };

            CampaignCriterionPage targets = campaignCriterionService.get(selector);
            List <GeoTarget>      list    = PopulateTargetList(targets, campaignId);

            return(list);
        }
Пример #3
0
        private List <string> ExtractTargetIds(CampaignCriterionPage targets, string campaignId)
        {
            List <string> idList = new List <string>();

            for (int i = 0; i < targets.totalNumEntries; i++)
            {
                if (targets.entries[i].campaignId == Convert.ToInt64(campaignId) && targets.entries[i].criterion.type == CriterionType.LOCATION)
                {
                    idList.Add(targets.entries[i].criterion.id.ToString());
                }
            }

            return(idList);
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign from which targeting
        /// criteria are retrieved.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            using (CampaignCriterionService campaignCriterionService =
                       (CampaignCriterionService)user.GetService(
                           AdWordsService.v201802.CampaignCriterionService)) {
                // Create the selector.
                Selector selector = new Selector()
                {
                    fields = new string[] {
                        Criterion.Fields.Id, Criterion.Fields.CriteriaType, CampaignCriterion.Fields.CampaignId
                    },
                    predicates = new Predicate[] {
                        Predicate.Equals(CampaignCriterion.Fields.CampaignId, campaignId)
                    },
                    paging = Paging.Default
                };

                CampaignCriterionPage page = new CampaignCriterionPage();

                try {
                    do
                    {
                        // Get all campaign targets.
                        page = campaignCriterionService.get(selector);

                        // Display the results.
                        if (page != null && page.entries != null)
                        {
                            int i = selector.paging.startIndex;
                            foreach (CampaignCriterion campaignCriterion in page.entries)
                            {
                                string negative =
                                    (campaignCriterion is NegativeCampaignCriterion) ? "Negative " : "";
                                Console.WriteLine("{0}) {1}Campaign criterion with id = '{2}' and Type = {3} " +
                                                  "was found for campaign id '{4}'",
                                                  i + 1, negative, campaignCriterion.criterion.id,
                                                  campaignCriterion.criterion.type, campaignCriterion.campaignId);
                                i++;
                            }
                        }
                        selector.paging.IncreaseOffset();
                    } while (selector.paging.startIndex < page.totalNumEntries);
                    Console.WriteLine("Number of campaign targeting criteria found: {0}",
                                      page.totalNumEntries);
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed to get campaign targeting criteria.", e);
                }
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign from which targeting
        /// criteria are retrieved.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the CampaignCriterionService.
            CampaignCriterionService campaignCriterionService =
                (CampaignCriterionService)user.GetService(
                    AdWordsService.v201506.CampaignCriterionService);

            Selector selector = new Selector()
            {
                fields = new string[] {
                    CampaignCriterion.Fields.CampaignId, Criterion.Fields.Id,
                    Criterion.Fields.CriteriaType, Placement.Fields.PlacementUrl
                },
                predicates = new Predicate[] {
                    Predicate.Equals(CampaignCriterion.Fields.CampaignId, campaignId.ToString()),
                    Predicate.Equals(Criterion.Fields.CriteriaType, "PLACEMENT")
                },
                paging = Paging.Default
            };

            CampaignCriterionPage page = new CampaignCriterionPage();

            try {
                do
                {
                    // Get all campaign targets.
                    page = campaignCriterionService.get(selector);

                    // Display the results.
                    if (page != null && page.entries != null)
                    {
                        int i = selector.paging.startIndex;
                        foreach (CampaignCriterion campaignCriterion in page.entries)
                        {
                            Placement placement = campaignCriterion.criterion as Placement;

                            Console.WriteLine("{0}) Placement with ID {1} and url {2} was found.", i + 1,
                                              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 get campaign targeting criteria.", e);
            }
        }
Пример #6
0
        private List <GeoTarget> PopulateTargetList(CampaignCriterionPage targets, string campaignId)
        {
            var           list      = new List <GeoTarget>();
            List <string> targetIds = ExtractTargetIds(targets, campaignId);

            if (targetIds != null && targetIds.Count > 0)
            {
                list = _locationNameHelper.GetLocationNamesByTargetIds(targetIds);

                return(list);
            }
            else
            {
                throw new ValidationException("Campaign not found.");
            }
        }
    /// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <param name="campaignId">Id of the campaign from which targeting
    /// criteria are retrieved.</param>
    public void Run(AdWordsUser user, long campaignId) {
      // Get the CampaignCriterionService.
      CampaignCriterionService campaignCriterionService =
          (CampaignCriterionService) user.GetService(
              AdWordsService.v201509.CampaignCriterionService);

      Selector selector = new Selector() {
        fields = new string[] {
          CampaignCriterion.Fields.CampaignId, Criterion.Fields.Id,
          Criterion.Fields.CriteriaType, Placement.Fields.PlacementUrl
        },
        predicates = new Predicate[] {
          Predicate.Equals(CampaignCriterion.Fields.CampaignId, campaignId.ToString()),
          Predicate.Equals(Criterion.Fields.CriteriaType, "PLACEMENT")
        },
        paging = Paging.Default
      };

      CampaignCriterionPage page = new CampaignCriterionPage();

      try {
        do {
          // Get all campaign targets.
          page = campaignCriterionService.get(selector);

          // Display the results.
          if (page != null && page.entries != null) {
            int i = selector.paging.startIndex;
            foreach (CampaignCriterion campaignCriterion in page.entries) {
              Placement placement = campaignCriterion.criterion as Placement;

              Console.WriteLine("{0}) Placement with ID {1} and url {2} was found.", i + 1,
                  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 get campaign targeting criteria.", e);
      }
    }
    /// <summary>
    /// Runs the code example.
    /// </summary>
    /// <param name="user">The AdWords user.</param>
    /// <param name="campaignId">Id of the campaign from which targeting
    /// criteria are retrieved.</param>
    public void Run(AdWordsUser user, long campaignId) {
      // Get the CampaignCriterionService.
      CampaignCriterionService campaignCriterionService =
          (CampaignCriterionService) user.GetService(
              AdWordsService.v201509.CampaignCriterionService);

      // Create the selector.
      Selector selector = new Selector() {
        fields = new string[] {
          Criterion.Fields.Id, Criterion.Fields.CriteriaType, CampaignCriterion.Fields.CampaignId
        },
        predicates = new Predicate[] {
          Predicate.Equals(CampaignCriterion.Fields.CampaignId, campaignId)
        },
        paging = Paging.Default
      };

      CampaignCriterionPage page = new CampaignCriterionPage();

      try {
        do {
          // Get all campaign targets.
          page = campaignCriterionService.get(selector);

          // Display the results.
          if (page != null && page.entries != null) {
            int i = selector.paging.startIndex;
            foreach (CampaignCriterion campaignCriterion in page.entries) {
              string negative = (campaignCriterion is NegativeCampaignCriterion) ? "Negative " : "";
              Console.WriteLine("{0}) {1}Campaign criterion with id = '{2}' and Type = {3} was " +
                  " found for campaign id '{4}'", i + 1, negative, campaignCriterion.criterion.id,
                  campaignCriterion.criterion.type, campaignCriterion.campaignId);
              i++;
            }
          }
          selector.paging.IncreaseOffset();
        } while (selector.paging.startIndex < page.totalNumEntries);
        Console.WriteLine("Number of campaign targeting criteria found: {0}",
            page.totalNumEntries);
      } catch (Exception e) {
        throw new System.ApplicationException("Failed to get campaign targeting criteria.", e);
      }
    }
Пример #9
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the campaign from which targeting
        /// criteria are retrieved.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the CampaignCriterionService.
            CampaignCriterionService campaignCriterionService =
                (CampaignCriterionService)user.GetService(
                    AdWordsService.v201402.CampaignCriterionService);

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

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

            // Set the filters.
            Predicate campaignPredicate = new Predicate();

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

            Predicate placementPredicate = new Predicate();

            placementPredicate.field     = "CriteriaType";
            placementPredicate.@operator = PredicateOperator.EQUALS;
            placementPredicate.values    = new string[] { "PLACEMENT" };

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

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

            int offset   = 0;
            int pageSize = 500;

            CampaignCriterionPage page = new CampaignCriterionPage();

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

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

                    // Display the results.
                    if (page != null && page.entries != null)
                    {
                        int i = offset;
                        foreach (CampaignCriterion campaignCriterion in page.entries)
                        {
                            Placement placement = campaignCriterion.criterion as Placement;

                            Console.WriteLine("{0}) Placement with ID {1} and url {2} was found.", i,
                                              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 get campaign targeting criteria.", ex);
            }
        }
Пример #10
0
        private void button2_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;
            }

            CampaignCriterionService campaignCriterionService = (CampaignCriterionService)User.GetService(AdWordsService.v201302.CampaignCriterionService);

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

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

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

            CampaignCriterionPage page = new CampaignCriterionPage();

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

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

                    // Display the results.
                    if (page != null && page.entries != null)
                    {
                        int i = offset;
                        foreach (CampaignCriterion campaignCriterion in page.entries)
                        {
                            string negative = (campaignCriterion is NegativeCampaignCriterion) ? "Negative " : "";
                            Console.WriteLine("{0}) {1}Campaign criterion with id = '{2}' and Type = {3} was " +
                                              " found for campaign id '{4}'", i, negative, campaignCriterion.criterion.id,
                                              campaignCriterion.criterion.type, campaignCriterion.campaignId);
                            i++;
                        }
                    }
                    offset += pageSize;
                } while (offset < page.totalNumEntries);
                Console.WriteLine("Number of campaign targeting criteria found: {0}", page.totalNumEntries);
            }
            catch (Exception ex)
            {
                throw new System.ApplicationException("Failed to get campaign targeting criteria.", ex);
            }
        }