/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId1">Id of the campaign to which labels are /// added.</param> /// <param name="campaignId2">Id of the campaign to which labels are /// added.</param> /// <param name="labelId">ID of the label to apply.</param> public void Run(AdWordsUser user, long campaignId1, long campaignId2, long labelId) { using (CampaignService campaignService = (CampaignService)user.GetService(AdWordsService.v201809.CampaignService)) { // Create label operations. List <CampaignLabelOperation> operations = new List <CampaignLabelOperation>(); foreach (long campaignId in new long[] { campaignId1, campaignId2 }) { CampaignLabel campaignLabel = new CampaignLabel { campaignId = campaignId, labelId = labelId }; CampaignLabelOperation operation = new CampaignLabelOperation { operand = campaignLabel, @operator = Operator.ADD }; operations.Add(operation); } try { CampaignLabelReturnValue retval = campaignService.mutateLabel(operations.ToArray()); // Display campaign labels. if (retval != null && retval.value != null) { foreach (CampaignLabel newCampaignLabel in retval.value) { Console.WriteLine( "Campaign label for campaign ID {0} and label ID {1} was added.\n", newCampaignLabel.campaignId, newCampaignLabel.labelId); } } else { Console.WriteLine("No campaign labels were added."); } } catch (Exception e) { throw new System.ApplicationException("Failed to add campaign label.", e); } } }
/// <summary>Snippet for MutateCampaignLabels</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void MutateCampaignLabels() { // Create client CampaignLabelServiceClient campaignLabelServiceClient = CampaignLabelServiceClient.Create(); // Initialize request argument(s) string customerId = ""; IEnumerable <CampaignLabelOperation> operations = new CampaignLabelOperation[] { new CampaignLabelOperation(), }; // Make the request MutateCampaignLabelsResponse response = campaignLabelServiceClient.MutateCampaignLabels(customerId, operations); }
/// <summary>Snippet for MutateCampaignLabelsAsync</summary> public async Task MutateCampaignLabelsAsync() { // Snippet: MutateCampaignLabelsAsync(string, IEnumerable<CampaignLabelOperation>, CallSettings) // Additional: MutateCampaignLabelsAsync(string, IEnumerable<CampaignLabelOperation>, CancellationToken) // Create client CampaignLabelServiceClient campaignLabelServiceClient = await CampaignLabelServiceClient.CreateAsync(); // Initialize request argument(s) string customerId = ""; IEnumerable <CampaignLabelOperation> operations = new CampaignLabelOperation[] { new CampaignLabelOperation(), }; // Make the request MutateCampaignLabelsResponse response = await campaignLabelServiceClient.MutateCampaignLabelsAsync(customerId, operations); // End snippet }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId1">Id of the campaign to which labels are /// added.</param> /// <param name="campaignId2">Id of the campaign to which labels are /// added.</param> /// <param name="labelId">ID of the label to apply.</param> public void Run(AdWordsUser user, long campaignId1, long campaignId2, long labelId) { try { // Get the CampaignService. CampaignService campaignService = (CampaignService) user.GetService(AdWordsService.v201509.CampaignService); // Create label operations. List<CampaignLabelOperation> operations = new List<CampaignLabelOperation>(); foreach (long campaignId in new long[] { campaignId1, campaignId2 }) { CampaignLabel campaignLabel = new CampaignLabel(); campaignLabel.campaignId = campaignId; campaignLabel.labelId = labelId; CampaignLabelOperation operation = new CampaignLabelOperation(); operation.operand = campaignLabel; operation.@operator = Operator.ADD; operations.Add(operation); } CampaignLabelReturnValue retval = campaignService.mutateLabel( operations.ToArray()); // Display campaign labels. if (retval != null && retval.value != null) { foreach (CampaignLabel newCampaignLabel in retval.value) { Console.WriteLine("Campaign label for campaign ID {0} and label ID {1} was added.\n", newCampaignLabel.campaignId, newCampaignLabel.labelId); } } else { Console.WriteLine("No campaign labels were added."); } } catch (Exception e) { throw new System.ApplicationException("Failed to add campaign label.", e); } }