/// <summary>
        /// Attaches a shared set to a campaign.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">The campaign id.</param>
        /// <param name="sharedSetId">The shared set id.</param>
        /// <returns>A CampaignSharedSet object that represents a binding between
        /// the specified campaign and the shared set.</returns>
        public CampaignSharedSet AttachSharedSetToCampaign(AdWordsUser user, long campaignId,
                                                           long sharedSetId)
        {
            using (CampaignSharedSetService campaignSharedSetService =
                       (CampaignSharedSetService)user.GetService(AdWordsService.v201802
                                                                 .CampaignSharedSetService))
            {
                CampaignSharedSet campaignSharedSet = new CampaignSharedSet
                {
                    campaignId  = campaignId,
                    sharedSetId = sharedSetId
                };

                CampaignSharedSetOperation operation = new CampaignSharedSetOperation
                {
                    @operator = Operator.ADD,
                    operand   = campaignSharedSet
                };

                CampaignSharedSetReturnValue retval = campaignSharedSetService.mutate(
                    new CampaignSharedSetOperation[]
                {
                    operation
                });
                return(retval.value[0]);
            }
        }
예제 #2
0
        /// <summary>
        /// Gets the shared set IDs associated with a campaign.
        /// </summary>
        /// <param name="user">The user that owns the campaign.</param>
        /// <param name="campaignId">The campaign identifier.</param>
        /// <returns>The list of shared set IDs associated with the campaign.</returns>
        private List <string> GetSharedSetIds(AdWordsUser user, long campaignId)
        {
            CampaignSharedSetService campaignSharedSetService =
                (CampaignSharedSetService)user.GetService(
                    AdWordsService.v201506.CampaignSharedSetService);

            Selector selector = new Selector()
            {
                fields     = new string[] { "SharedSetId", "CampaignId", "SharedSetName", "SharedSetType" },
                predicates = new Predicate[] {
                    new Predicate()
                    {
                        field     = "CampaignId",
                        @operator = PredicateOperator.EQUALS,
                        values    = new string[] { campaignId.ToString() }
                    },
                    new Predicate()
                    {
                        field     = "SharedSetType",
                        @operator = PredicateOperator.IN,
                        values    = new string[] { SharedSetType.NEGATIVE_KEYWORDS.ToString() }
                    }
                }
            };

            List <string> sharedSetIds = new List <string>();

            int offset   = 0;
            int pageSize = 500;

            CampaignSharedSetPage page = new CampaignSharedSetPage();

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

                    // Get the campaigns.
                    page = campaignSharedSetService.get(selector);

                    // Display the results.
                    if (page != null && page.entries != null)
                    {
                        int i = offset;
                        foreach (CampaignSharedSet campaignSharedSet in page.entries)
                        {
                            sharedSetIds.Add(campaignSharedSet.sharedSetId.ToString());
                            Console.WriteLine("Campaign shared set ID {0} and name '{1}' found for campaign " +
                                              "ID {2}.\n", campaignSharedSet.sharedSetId, campaignSharedSet.sharedSetName,
                                              campaignSharedSet.campaignId);
                        }
                    }
                    offset += pageSize;
                } while (offset < page.totalNumEntries);
                return(sharedSetIds);
            } catch (Exception e) {
                throw new Exception("Failed to get shared set ids for campaign.", e);
            }
        }
예제 #3
0
        /// <summary>
        /// Gets the shared set IDs associated with a campaign.
        /// </summary>
        /// <param name="user">The user that owns the campaign.</param>
        /// <param name="campaignId">The campaign identifier.</param>
        /// <returns>The list of shared set IDs associated with the campaign.</returns>
        private List <string> GetSharedSetIds(AdWordsUser user, long campaignId)
        {
            CampaignSharedSetService campaignSharedSetService =
                (CampaignSharedSetService)user.GetService(
                    AdWordsService.v201509.CampaignSharedSetService);

            Selector selector = new Selector()
            {
                fields = new string[] {
                    CampaignSharedSet.Fields.SharedSetId,
                    CampaignSharedSet.Fields.CampaignId,
                    CampaignSharedSet.Fields.SharedSetName,
                    CampaignSharedSet.Fields.SharedSetType
                },
                predicates = new Predicate[] {
                    Predicate.Equals(CampaignSharedSet.Fields.CampaignId, campaignId),
                    Predicate.In(CampaignSharedSet.Fields.SharedSetType,
                                 new string[] { SharedSetType.NEGATIVE_KEYWORDS.ToString() }),
                },
                paging = Paging.Default,
            };

            List <string>         sharedSetIds = new List <string>();
            CampaignSharedSetPage page         = new CampaignSharedSetPage();

            try {
                do
                {
                    // Get the campaigns.
                    page = campaignSharedSetService.get(selector);

                    // Display the results.
                    if (page != null && page.entries != null)
                    {
                        int i = selector.paging.startIndex;
                        foreach (CampaignSharedSet campaignSharedSet in page.entries)
                        {
                            sharedSetIds.Add(campaignSharedSet.sharedSetId.ToString());
                            Console.WriteLine("{0}) Campaign shared set ID {1} and name '{2}' found for " +
                                              "campaign ID {3}.\n", i + 1, campaignSharedSet.sharedSetId,
                                              campaignSharedSet.sharedSetName, campaignSharedSet.campaignId);
                            i++;
                        }
                    }
                    selector.paging.IncreaseOffset();
                } while (selector.paging.startIndex < page.totalNumEntries);
                return(sharedSetIds);
            } catch (Exception e) {
                throw new Exception("Failed to get shared set ids for campaign.", e);
            }
        }
예제 #4
0
        /// <summary>
        /// Detaches the shared set from campaign.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">The campaign identifier.</param>
        /// <param name="sharedSetId">The shared set identifier.</param>
        public void DetachSharedSetFromCampaign(AdWordsUser user, long campaignId, long sharedSetId)
        {
            // Get the CampaignSharedSetService.
            CampaignSharedSetService campaignSharedSetService = (CampaignSharedSetService)
                                                                user.GetService(AdWordsService.v201607.CampaignSharedSetService);

            CampaignSharedSet campaignSharedSet = new CampaignSharedSet();

            campaignSharedSet.campaignId  = campaignId;
            campaignSharedSet.sharedSetId = sharedSetId;

            CampaignSharedSetOperation operation = new CampaignSharedSetOperation();

            operation.@operator = Operator.REMOVE;
            operation.operand   = campaignSharedSet;

            campaignSharedSetService.mutate(new CampaignSharedSetOperation[] { operation });
        }
        /// <summary>
        /// Attaches a shared set to a campaign.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">The campaign id.</param>
        /// <param name="sharedSetId">The shared set id.</param>
        /// <returns>A CampaignSharedSet object that represents a binding between
        /// the specified campaign and the shared set.</returns>
        public CampaignSharedSet AttachSharedSetToCampaign(AdWordsUser user, long campaignId,
                                                           long sharedSetId)
        {
            using (CampaignSharedSetService campaignSharedSetService = (CampaignSharedSetService)
                                                                       user.GetService(AdWordsService.v201708.CampaignSharedSetService)) {
                CampaignSharedSet campaignSharedSet = new CampaignSharedSet();
                campaignSharedSet.campaignId  = campaignId;
                campaignSharedSet.sharedSetId = sharedSetId;

                CampaignSharedSetOperation operation = new CampaignSharedSetOperation();
                operation.@operator = Operator.ADD;
                operation.operand   = campaignSharedSet;

                CampaignSharedSetReturnValue retval = campaignSharedSetService.mutate(
                    new CampaignSharedSetOperation[] { operation });
                return(retval.value[0]);
            }
        }