/// <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>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the ad group to which ads are added.
        /// </param>
        public void Run(AdWordsUser user, long campaignId)
        {
            try {
                SharedSet sharedSet = CreateSharedKeywordSet(user);

                Console.WriteLine("Shared set with id = {0}, name = {1}, type = {2}, status = {3} " +
                                  "was created.", sharedSet.sharedSetId, sharedSet.name, sharedSet.type,
                                  sharedSet.status);

                string[]          keywordTexts   = new string[] { "mars cruise", "mars hotels" };
                SharedCriterion[] sharedCriteria = AddKeywordsToSharedSet(user, sharedSet.sharedSetId,
                                                                          keywordTexts);
                foreach (SharedCriterion sharedCriterion in sharedCriteria)
                {
                    Keyword keyword = sharedCriterion.criterion as Keyword;
                    Console.WriteLine("Added keyword with id = {0}, text = {1}, matchtype = {2} to " +
                                      "shared set with id = {3}.", keyword.id, keyword.text, keyword.matchType,
                                      sharedSet.sharedSetId);
                }
                CampaignSharedSet attachedSharedSet = AttachSharedSetToCampaign(user, campaignId,
                                                                                sharedSet.sharedSetId);

                Console.WriteLine("Attached shared set with id = {0} to campaign id {1}.",
                                  attachedSharedSet.sharedSetId, attachedSharedSet.campaignId);
            } catch (Exception ex) {
                throw new System.ApplicationException("Failed to create shared keyword set and attach " +
                                                      "it to a campaign.", ex);
            }
        }
示例#3
0
 /// <summary>Snippet for GetCampaignSharedSet</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetCampaignSharedSet()
 {
     // Create client
     CampaignSharedSetServiceClient campaignSharedSetServiceClient = CampaignSharedSetServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER_ID]/campaignSharedSets/[CAMPAIGN_ID]~[SHARED_SET_ID]";
     // Make the request
     CampaignSharedSet response = campaignSharedSetServiceClient.GetCampaignSharedSet(resourceName);
 }
示例#4
0
 /// <summary>Snippet for GetCampaignSharedSet</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetCampaignSharedSetResourceNames()
 {
     // Create client
     CampaignSharedSetServiceClient campaignSharedSetServiceClient = CampaignSharedSetServiceClient.Create();
     // Initialize request argument(s)
     CampaignSharedSetName resourceName = CampaignSharedSetName.FromCustomerCampaignSharedSet("[CUSTOMER_ID]", "[CAMPAIGN_ID]", "[SHARED_SET_ID]");
     // Make the request
     CampaignSharedSet response = campaignSharedSetServiceClient.GetCampaignSharedSet(resourceName);
 }
        /// <summary>Snippet for GetCampaignSharedSetAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetCampaignSharedSetAsync()
        {
            // Create client
            CampaignSharedSetServiceClient campaignSharedSetServiceClient = await CampaignSharedSetServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/campaignSharedSets/[CAMPAIGN_SHARED_SET]";
            // Make the request
            CampaignSharedSet response = await campaignSharedSetServiceClient.GetCampaignSharedSetAsync(resourceName);
        }
示例#6
0
        /// <summary>Snippet for GetCampaignSharedSetAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetCampaignSharedSetResourceNamesAsync()
        {
            // Create client
            CampaignSharedSetServiceClient campaignSharedSetServiceClient = await CampaignSharedSetServiceClient.CreateAsync();

            // Initialize request argument(s)
            CampaignSharedSetName resourceName = CampaignSharedSetName.FromCustomerCampaignSharedSet("[CUSTOMER]", "[CAMPAIGN_SHARED_SET]");
            // Make the request
            CampaignSharedSet response = await campaignSharedSetServiceClient.GetCampaignSharedSetAsync(resourceName);
        }
 /// <summary>Snippet for GetCampaignSharedSet</summary>
 public void GetCampaignSharedSet()
 {
     // Snippet: GetCampaignSharedSet(string, CallSettings)
     // Create client
     CampaignSharedSetServiceClient campaignSharedSetServiceClient = CampaignSharedSetServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER]/campaignSharedSets/[CAMPAIGN_SHARED_SET]";
     // Make the request
     CampaignSharedSet response = campaignSharedSetServiceClient.GetCampaignSharedSet(resourceName);
     // End snippet
 }
 /// <summary>Snippet for GetCampaignSharedSet</summary>
 public void GetCampaignSharedSetResourceNames()
 {
     // Snippet: GetCampaignSharedSet(CampaignSharedSetName, CallSettings)
     // Create client
     CampaignSharedSetServiceClient campaignSharedSetServiceClient = CampaignSharedSetServiceClient.Create();
     // Initialize request argument(s)
     CampaignSharedSetName resourceName = CampaignSharedSetName.FromCustomerCampaignSharedSet("[CUSTOMER]", "[CAMPAIGN_SHARED_SET]");
     // Make the request
     CampaignSharedSet response = campaignSharedSetServiceClient.GetCampaignSharedSet(resourceName);
     // End snippet
 }
 /// <summary>Snippet for GetCampaignSharedSet</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetCampaignSharedSetRequestObject()
 {
     // Create client
     CampaignSharedSetServiceClient campaignSharedSetServiceClient = CampaignSharedSetServiceClient.Create();
     // Initialize request argument(s)
     GetCampaignSharedSetRequest request = new GetCampaignSharedSetRequest
     {
         ResourceNameAsCampaignSharedSetName = CampaignSharedSetName.FromCustomerCampaignSharedSet("[CUSTOMER]", "[CAMPAIGN_SHARED_SET]"),
     };
     // Make the request
     CampaignSharedSet response = campaignSharedSetServiceClient.GetCampaignSharedSet(request);
 }
        /// <summary>Snippet for GetCampaignSharedSetAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetCampaignSharedSetRequestObjectAsync()
        {
            // Create client
            CampaignSharedSetServiceClient campaignSharedSetServiceClient = await CampaignSharedSetServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetCampaignSharedSetRequest request = new GetCampaignSharedSetRequest
            {
                ResourceNameAsCampaignSharedSetName = CampaignSharedSetName.FromCustomerCampaignSharedSet("[CUSTOMER_ID]", "[CAMPAIGN_ID]", "[SHARED_SET_ID]"),
            };
            // Make the request
            CampaignSharedSet response = await campaignSharedSetServiceClient.GetCampaignSharedSetAsync(request);
        }
        /// <summary>Snippet for GetCampaignSharedSetAsync</summary>
        public async Task GetCampaignSharedSetResourceNamesAsync()
        {
            // Snippet: GetCampaignSharedSetAsync(CampaignSharedSetName, CallSettings)
            // Additional: GetCampaignSharedSetAsync(CampaignSharedSetName, CancellationToken)
            // Create client
            CampaignSharedSetServiceClient campaignSharedSetServiceClient = await CampaignSharedSetServiceClient.CreateAsync();

            // Initialize request argument(s)
            CampaignSharedSetName resourceName = CampaignSharedSetName.FromCustomerCampaignSharedSet("[CUSTOMER]", "[CAMPAIGN_SHARED_SET]");
            // Make the request
            CampaignSharedSet response = await campaignSharedSetServiceClient.GetCampaignSharedSetAsync(resourceName);

            // End snippet
        }
        /// <summary>Snippet for GetCampaignSharedSetAsync</summary>
        public async Task GetCampaignSharedSetAsync()
        {
            // Snippet: GetCampaignSharedSetAsync(string, CallSettings)
            // Additional: GetCampaignSharedSetAsync(string, CancellationToken)
            // Create client
            CampaignSharedSetServiceClient campaignSharedSetServiceClient = await CampaignSharedSetServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/campaignSharedSets/[CAMPAIGN_SHARED_SET]";
            // Make the request
            CampaignSharedSet response = await campaignSharedSetServiceClient.GetCampaignSharedSetAsync(resourceName);

            // End snippet
        }
示例#13
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]);
            }
        }
        public void GetCampaignSharedSet2()
        {
            Mock <CampaignSharedSetService.CampaignSharedSetServiceClient> mockGrpcClient = new Mock <CampaignSharedSetService.CampaignSharedSetServiceClient>(MockBehavior.Strict);
            GetCampaignSharedSetRequest request = new GetCampaignSharedSetRequest
            {
                ResourceName = new CampaignSharedSetName("[CUSTOMER]", "[CAMPAIGN_SHARED_SET]").ToString(),
            };
            CampaignSharedSet expectedResponse = new CampaignSharedSet
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetCampaignSharedSet(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            CampaignSharedSetServiceClient client = new CampaignSharedSetServiceClientImpl(mockGrpcClient.Object, null);
            CampaignSharedSet response            = client.GetCampaignSharedSet(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public async Task GetCampaignSharedSetAsync()
        {
            Mock <CampaignSharedSetService.CampaignSharedSetServiceClient> mockGrpcClient = new Mock <CampaignSharedSetService.CampaignSharedSetServiceClient>(MockBehavior.Strict);
            GetCampaignSharedSetRequest expectedRequest = new GetCampaignSharedSetRequest
            {
                ResourceName = new CampaignSharedSetName("[CUSTOMER]", "[CAMPAIGN_SHARED_SET]").ToString(),
            };
            CampaignSharedSet expectedResponse = new CampaignSharedSet
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetCampaignSharedSetAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <CampaignSharedSet>(Task.FromResult(expectedResponse), null, null, null, null));
            CampaignSharedSetServiceClient client   = new CampaignSharedSetServiceClientImpl(mockGrpcClient.Object, null);
            string            formattedResourceName = new CampaignSharedSetName("[CUSTOMER]", "[CAMPAIGN_SHARED_SET]").ToString();
            CampaignSharedSet response = await client.GetCampaignSharedSetAsync(formattedResourceName);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
示例#17
0
        /// <summary>
        /// Detaches the shared set from campaign.
        /// </summary>
        /// <param name="user">The 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.v201601.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>
        /// 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>
        /// 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)
        {
            // Get the CampaignSharedSetService.
              CampaignSharedSetService campaignSharedSetService = (CampaignSharedSetService)
              user.GetService(AdWordsService.v201601.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];
        }