/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign to which keywords are added.</param> public void Run(AdWordsUser user, long campaignId) { try { // Create a shared set. 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); // Add new keywords to the shared set. 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); } // Attach the shared set to the campaign. 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 e) { throw new System.ApplicationException("Failed to create shared keyword set and attach " + "it to a campaign.", e); } }
/// <summary>Snippet for GetSharedSet</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void GetSharedSetResourceNames() { // Create client SharedSetServiceClient sharedSetServiceClient = SharedSetServiceClient.Create(); // Initialize request argument(s) SharedSetName resourceName = SharedSetName.FromCustomerSharedSet("[CUSTOMER]", "[SHARED_SET]"); // Make the request SharedSet response = sharedSetServiceClient.GetSharedSet(resourceName); }
/// <summary>Snippet for GetSharedSet</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void GetSharedSet() { // Create client SharedSetServiceClient sharedSetServiceClient = SharedSetServiceClient.Create(); // Initialize request argument(s) string resourceName = "customers/[CUSTOMER_ID]/sharedSets/[SHARED_SET_ID]"; // Make the request SharedSet response = sharedSetServiceClient.GetSharedSet(resourceName); }
/// <summary>Snippet for GetSharedSetAsync</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 GetSharedSetAsync() { // Create client SharedSetServiceClient sharedSetServiceClient = await SharedSetServiceClient.CreateAsync(); // Initialize request argument(s) string resourceName = "customers/[CUSTOMER_ID]/sharedSets/[SHARED_SET_ID]"; // Make the request SharedSet response = await sharedSetServiceClient.GetSharedSetAsync(resourceName); }
/// <summary>Snippet for GetSharedSetAsync</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 GetSharedSetResourceNamesAsync() { // Create client SharedSetServiceClient sharedSetServiceClient = await SharedSetServiceClient.CreateAsync(); // Initialize request argument(s) SharedSetName resourceName = SharedSetName.FromCustomerSharedSet("[CUSTOMER_ID]", "[SHARED_SET_ID]"); // Make the request SharedSet response = await sharedSetServiceClient.GetSharedSetAsync(resourceName); }
/// <summary>Snippet for GetSharedSet</summary> public void GetSharedSet() { // Snippet: GetSharedSet(string, CallSettings) // Create client SharedSetServiceClient sharedSetServiceClient = SharedSetServiceClient.Create(); // Initialize request argument(s) string resourceName = "customers/[CUSTOMER]/sharedSets/[SHARED_SET]"; // Make the request SharedSet response = sharedSetServiceClient.GetSharedSet(resourceName); // End snippet }
/// <summary>Snippet for GetSharedSet</summary> public void GetSharedSetResourceNames() { // Snippet: GetSharedSet(SharedSetName, CallSettings) // Create client SharedSetServiceClient sharedSetServiceClient = SharedSetServiceClient.Create(); // Initialize request argument(s) SharedSetName resourceName = SharedSetName.FromCustomerSharedSet("[CUSTOMER_ID]", "[SHARED_SET_ID]"); // Make the request SharedSet response = sharedSetServiceClient.GetSharedSet(resourceName); // End snippet }
/// <summary>Snippet for GetSharedSet</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void GetSharedSetRequestObject() { // Create client SharedSetServiceClient sharedSetServiceClient = SharedSetServiceClient.Create(); // Initialize request argument(s) GetSharedSetRequest request = new GetSharedSetRequest { ResourceNameAsSharedSetName = SharedSetName.FromCustomerSharedSet("[CUSTOMER_ID]", "[SHARED_SET_ID]"), }; // Make the request SharedSet response = sharedSetServiceClient.GetSharedSet(request); }
/// <summary>Snippet for GetSharedSetAsync</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 GetSharedSetRequestObjectAsync() { // Create client SharedSetServiceClient sharedSetServiceClient = await SharedSetServiceClient.CreateAsync(); // Initialize request argument(s) GetSharedSetRequest request = new GetSharedSetRequest { ResourceNameAsSharedSetName = SharedSetName.FromCustomerSharedSet("[CUSTOMER]", "[SHARED_SET]"), }; // Make the request SharedSet response = await sharedSetServiceClient.GetSharedSetAsync(request); }
/// <summary>Snippet for GetSharedSetAsync</summary> public async Task GetSharedSetAsync() { // Snippet: GetSharedSetAsync(string, CallSettings) // Additional: GetSharedSetAsync(string, CancellationToken) // Create client SharedSetServiceClient sharedSetServiceClient = await SharedSetServiceClient.CreateAsync(); // Initialize request argument(s) string resourceName = "customers/[CUSTOMER_ID]/sharedSets/[SHARED_SET_ID]"; // Make the request SharedSet response = await sharedSetServiceClient.GetSharedSetAsync(resourceName); // End snippet }
/// <summary>Snippet for GetSharedSetAsync</summary> public async Task GetSharedSetResourceNamesAsync() { // Snippet: GetSharedSetAsync(SharedSetName, CallSettings) // Additional: GetSharedSetAsync(SharedSetName, CancellationToken) // Create client SharedSetServiceClient sharedSetServiceClient = await SharedSetServiceClient.CreateAsync(); // Initialize request argument(s) SharedSetName resourceName = SharedSetName.FromCustomerSharedSet("[CUSTOMER_ID]", "[SHARED_SET_ID]"); // Make the request SharedSet response = await sharedSetServiceClient.GetSharedSetAsync(resourceName); // End snippet }
/// <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(); 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]); } }
/// <summary> /// Deletes the shared set. /// </summary> /// <param name="user">The AdWords 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.v201607.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 }); }
/// <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.v201607.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); }
public void GetSharedSet2() { Mock <SharedSetService.SharedSetServiceClient> mockGrpcClient = new Mock <SharedSetService.SharedSetServiceClient>(MockBehavior.Strict); GetSharedSetRequest request = new GetSharedSetRequest { ResourceName = new SharedSetName("[CUSTOMER]", "[SHARED_SET]").ToString(), }; SharedSet expectedResponse = new SharedSet { ResourceName = "resourceName2625949903", }; mockGrpcClient.Setup(x => x.GetSharedSet(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); SharedSetServiceClient client = new SharedSetServiceClientImpl(mockGrpcClient.Object, null); SharedSet response = client.GetSharedSet(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async Task GetSharedSetAsync2() { Mock <SharedSetService.SharedSetServiceClient> mockGrpcClient = new Mock <SharedSetService.SharedSetServiceClient>(MockBehavior.Strict); GetSharedSetRequest request = new GetSharedSetRequest { ResourceName = new SharedSetName("[CUSTOMER]", "[SHARED_SET]").ToString(), }; SharedSet expectedResponse = new SharedSet { ResourceName = "resourceName2625949903", }; mockGrpcClient.Setup(x => x.GetSharedSetAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <SharedSet>(Task.FromResult(expectedResponse), null, null, null, null)); SharedSetServiceClient client = new SharedSetServiceClientImpl(mockGrpcClient.Object, null); SharedSet response = await client.GetSharedSetAsync(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <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]; }
/// <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> /// 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 }); }
/// <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; }
/// <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) { try { SharedCriterionServiceClient sharedCriterionService = client.GetService( Services.V3.SharedCriterionService); GoogleAdsServiceClient googleAdsService = client.GetService( Services.V3.GoogleAdsService); List <long?> sharedSetIds = new List <long?>(); List <string> criterionResources = new List <string>(); // First, retrieve all shared sets associated with the campaign. string sharedSetQuery = $"SELECT shared_set.id, shared_set.name FROM " + $"campaign_shared_set WHERE campaign.id = {campaignId}"; PagedEnumerable <SearchGoogleAdsResponse, GoogleAdsRow> sharedSetResponse = googleAdsService.Search(customerId.ToString(), sharedSetQuery); // Display the results. foreach (GoogleAdsRow googleAdsRow in sharedSetResponse) { SharedSet sharedSet = googleAdsRow.SharedSet; Console.WriteLine("Campaign shared set ID {0} and name '{1}' was found.", sharedSet.Id, sharedSet.Name); sharedSetIds.Add(sharedSet.Id); } // Next, retrieve shared criteria for all found shared sets. string sharedCriterionQuery = "SELECT shared_criterion.type, shared_criterion.keyword.text, " + "shared_criterion.keyword.match_type, shared_set.id FROM shared_criterion " + $"WHERE shared_set.id IN(" + string.Join(",", sharedSetIds.ConvertAll(x => x.ToString())) + ")"; PagedEnumerable <SearchGoogleAdsResponse, GoogleAdsRow> sharedCriterionResponse = googleAdsService.Search(customerId.ToString(), sharedCriterionQuery); // Display the results. foreach (GoogleAdsRow googleAdsRow in sharedCriterionResponse) { SharedCriterion sharedCriterion = googleAdsRow.SharedCriterion; if (sharedCriterion.Type == CriterionType.Keyword) { Console.WriteLine("Shared criterion with resource name '{0}' for " + "negative keyword with text '{1}' and match type '{2}' was found.", sharedCriterion.ResourceName, sharedCriterion.Keyword.Text, sharedCriterion.Keyword.MatchType); } else { Console.WriteLine("Shared criterion with resource name '{0}' was found.", sharedCriterion.ResourceName); } criterionResources.Add(sharedCriterion.ResourceName); } // Finally, remove the criteria. List <SharedCriterionOperation> operations = new List <SharedCriterionOperation>(); foreach (string criterionResource in criterionResources) { SharedCriterionOperation operation = new SharedCriterionOperation() { Remove = criterionResource }; operations.Add(operation); } MutateSharedCriteriaResponse response = sharedCriterionService.MutateSharedCriteria( customerId.ToString(), operations); foreach (MutateSharedCriterionResult result in response.Results) { Console.WriteLine($"Removed shared criterion {result.ResourceName}."); } } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); } }