Example #1
0
        /// <summary>
        /// Creates the shared keyword set.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <returns>A shared keyword set.</returns>
        public long CreateSharedKeywordSet(AdWordsUser user)
        {
            // Get the SharedSetService.
            SharedSetService sharedSetService = (SharedSetService)
                                                user.GetService(AdWordsService.v201603.SharedSetService);

            SharedSetOperation operation = new SharedSetOperation();

            operation.@operator = Operator.ADD;
            SharedSet sharedSet = new SharedSet();

            sharedSet.name    = "API Negative keyword list - " + GetTimeStampAlpha();
            sharedSet.type    = SharedSetType.NEGATIVE_KEYWORDS;
            operation.operand = sharedSet;

            SharedSetReturnValue retval = sharedSetService.mutate(
                new SharedSetOperation[] { operation });

            return(retval.value[0].sharedSetId);
        }
        /// <summary>
        /// Create a shared keyword set.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <returns>The shared set.</returns>
        public SharedSet CreateSharedKeywordSet(AdWordsUser user)
        {
            using (SharedSetService sharedSetService =
                       (SharedSetService)user.GetService(AdWordsService.v201802.SharedSetService))
            {
                SharedSetOperation operation = new SharedSetOperation
                {
                    @operator = Operator.ADD
                };
                SharedSet sharedSet = new SharedSet
                {
                    name = "API Negative keyword list - " + ExampleUtilities.GetRandomString(),
                    type = SharedSetType.NEGATIVE_KEYWORDS
                };
                operation.operand = sharedSet;

                SharedSetReturnValue retval = sharedSetService.mutate(new SharedSetOperation[]
                {
                    operation
                });
                return(retval.value[0]);
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="campaignId">The ID of the campaign for which shared criterion is updated.
        /// </param>
        public void Run(GoogleAdsClient client, long customerId, long campaignId)
        {
            SharedSetServiceClient sharedSetService = client.GetService(
                Services.V4.SharedSetService);
            SharedCriterionServiceClient sharedCriterionService =
                client.GetService(Services.V4.SharedCriterionService);
            CampaignSharedSetServiceClient campaignSharedSetService =
                client.GetService(Services.V4.CampaignSharedSetService);

            try
            {
                // Keywords to create a shared set of.
                string[] keywords = new string[] { "mars cruise", "mars hotels" };

                // Create shared negative keyword set.
                SharedSet sharedSet = new SharedSet()
                {
                    Name = "API Negative keyword list - " + ExampleUtilities.GetRandomString(),
                    Type = SharedSetType.NegativeKeywords,
                };
                SharedSetOperation operation = new SharedSetOperation()
                {
                    Create = sharedSet
                };

                MutateSharedSetsResponse sharedSetResponse = sharedSetService.MutateSharedSets(
                    customerId.ToString(), new SharedSetOperation[] { operation });

                string sharedSetResourceName = sharedSetResponse.Results[0].ResourceName;
                Console.WriteLine($"Created shared set {sharedSetResourceName}.");

                // Create negative keywords in the shared set.
                List <SharedCriterionOperation> criterionOperations =
                    new List <SharedCriterionOperation>();

                foreach (string keyword in keywords)
                {
                    SharedCriterion sharedCriterion = new SharedCriterion()
                    {
                        Keyword = new KeywordInfo()
                        {
                            Text      = keyword,
                            MatchType = KeywordMatchType.Broad
                        },
                        SharedSet = sharedSetResourceName
                    };
                    criterionOperations.Add(new SharedCriterionOperation()
                    {
                        Create = sharedCriterion
                    });
                }

                MutateSharedCriteriaResponse criteriaResponse =
                    sharedCriterionService.MutateSharedCriteria(
                        customerId.ToString(), criterionOperations);

                foreach (MutateSharedCriterionResult result in criteriaResponse.Results)
                {
                    Console.WriteLine($"Created shared criterion {result.ResourceName}.");
                }

                // Attach shared set to campaign.
                CampaignSharedSet campaignSet = new CampaignSharedSet()
                {
                    Campaign  = ResourceNames.Campaign(customerId, campaignId),
                    SharedSet = sharedSetResourceName
                };

                CampaignSharedSetOperation sharedSetoperation = new CampaignSharedSetOperation()
                {
                    Create = campaignSet
                };
                MutateCampaignSharedSetsResponse response =
                    campaignSharedSetService.MutateCampaignSharedSets(customerId.ToString(),
                                                                      new CampaignSharedSetOperation[] { sharedSetoperation });

                Console.WriteLine("Created campaign shared set {0}.",
                                  response.Results[0].ResourceName);
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
        /// <summary>
        /// Create a shared keyword set.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <returns>The shared set.</returns>
        public SharedSet CreateSharedKeywordSet(AdWordsUser user)
        {
            // Get the SharedSetService.
              SharedSetService sharedSetService = (SharedSetService)
              user.GetService(AdWordsService.v201601.SharedSetService);

              SharedSetOperation operation = new SharedSetOperation();
              operation.@operator = Operator.ADD;
              SharedSet sharedSet = new SharedSet();
              sharedSet.name = "API Negative keyword list - " + ExampleUtilities.GetRandomString();
              sharedSet.type = SharedSetType.NEGATIVE_KEYWORDS;
              operation.operand = sharedSet;

              SharedSetReturnValue retval = sharedSetService.mutate(new SharedSetOperation[] {operation});
              return retval.value[0];
        }
Example #5
0
        /// <summary>
        /// Deletes the shared set.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="sharedSetId">The shared set ID.</param>
        public void DeleteSharedSet(AdWordsUser user, long sharedSetId)
        {
            // Get the SharedSetService.
              SharedSetService sharedSetService = (SharedSetService)
              user.GetService(AdWordsService.v201601.SharedSetService);

              SharedSetOperation operation = new SharedSetOperation();
              operation.@operator = Operator.REMOVE;
              SharedSet sharedSet = new SharedSet();
              sharedSet.sharedSetId = sharedSetId;
              operation.operand = sharedSet;

              SharedSetReturnValue retval = sharedSetService.mutate(
              new SharedSetOperation[] { operation });
        }
Example #6
0
        /// <summary>
        /// Creates the shared keyword set.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <returns>A shared keyword set.</returns>
        public long CreateSharedKeywordSet(AdWordsUser user)
        {
            // Get the SharedSetService.
              SharedSetService sharedSetService = (SharedSetService)
              user.GetService(AdWordsService.v201601.SharedSetService);

              SharedSetOperation operation = new SharedSetOperation();
              operation.@operator = Operator.ADD;
              SharedSet sharedSet = new SharedSet();
              sharedSet.name = "API Negative keyword list - " + GetTimeStampAlpha();
              sharedSet.type = SharedSetType.NEGATIVE_KEYWORDS;
              operation.operand = sharedSet;

              SharedSetReturnValue retval = sharedSetService.mutate(
              new SharedSetOperation[] { operation });
              return retval.value[0].sharedSetId;
        }