/// <summary>Snippet for GetCampaignLabel</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetCampaignLabel()
 {
     // Create client
     CampaignLabelServiceClient campaignLabelServiceClient = CampaignLabelServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER_ID]/campaignLabels/[CAMPAIGN_ID]~[LABEL_ID]";
     // Make the request
     CampaignLabel response = campaignLabelServiceClient.GetCampaignLabel(resourceName);
 }
 /// <summary>Snippet for GetCampaignLabel</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetCampaignLabelResourceNames()
 {
     // Create client
     CampaignLabelServiceClient campaignLabelServiceClient = CampaignLabelServiceClient.Create();
     // Initialize request argument(s)
     CampaignLabelName resourceName = CampaignLabelName.FromCustomerCampaignLabel("[CUSTOMER]", "[CAMPAIGN_LABEL]");
     // Make the request
     CampaignLabel response = campaignLabelServiceClient.GetCampaignLabel(resourceName);
 }
        /// <summary>Snippet for GetCampaignLabelAsync</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 GetCampaignLabelAsync()
        {
            // Create client
            CampaignLabelServiceClient campaignLabelServiceClient = await CampaignLabelServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/campaignLabels/[CAMPAIGN_LABEL]";
            // Make the request
            CampaignLabel response = await campaignLabelServiceClient.GetCampaignLabelAsync(resourceName);
        }
示例#4
0
        /// <summary>Snippet for GetCampaignLabelAsync</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 GetCampaignLabelResourceNamesAsync()
        {
            // Create client
            CampaignLabelServiceClient campaignLabelServiceClient = await CampaignLabelServiceClient.CreateAsync();

            // Initialize request argument(s)
            CampaignLabelName resourceName = CampaignLabelName.FromCustomerCampaignLabel("[CUSTOMER_ID]", "[CAMPAIGN_ID]", "[LABEL_ID]");
            // Make the request
            CampaignLabel response = await campaignLabelServiceClient.GetCampaignLabelAsync(resourceName);
        }
        /// <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 GetCampaignLabel</summary>
 public void GetCampaignLabel()
 {
     // Snippet: GetCampaignLabel(string, CallSettings)
     // Create client
     CampaignLabelServiceClient campaignLabelServiceClient = CampaignLabelServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER]/campaignLabels/[CAMPAIGN_LABEL]";
     // Make the request
     CampaignLabel response = campaignLabelServiceClient.GetCampaignLabel(resourceName);
     // End snippet
 }
 /// <summary>Snippet for GetCampaignLabel</summary>
 public void GetCampaignLabelResourceNames()
 {
     // Snippet: GetCampaignLabel(CampaignLabelName, CallSettings)
     // Create client
     CampaignLabelServiceClient campaignLabelServiceClient = CampaignLabelServiceClient.Create();
     // Initialize request argument(s)
     CampaignLabelName resourceName = CampaignLabelName.FromCustomerCampaignLabel("[CUSTOMER_ID]", "[CAMPAIGN_ID]", "[LABEL_ID]");
     // Make the request
     CampaignLabel response = campaignLabelServiceClient.GetCampaignLabel(resourceName);
     // End snippet
 }
示例#8
0
 /// <summary>Snippet for GetCampaignLabel</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetCampaignLabelRequestObject()
 {
     // Create client
     CampaignLabelServiceClient campaignLabelServiceClient = CampaignLabelServiceClient.Create();
     // Initialize request argument(s)
     GetCampaignLabelRequest request = new GetCampaignLabelRequest
     {
         ResourceNameAsCampaignLabelName = CampaignLabelName.FromCustomerCampaignLabel("[CUSTOMER_ID]", "[CAMPAIGN_ID]", "[LABEL_ID]"),
     };
     // Make the request
     CampaignLabel response = campaignLabelServiceClient.GetCampaignLabel(request);
 }
示例#9
0
        /// <summary>Snippet for GetCampaignLabelAsync</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 GetCampaignLabelRequestObjectAsync()
        {
            // Create client
            CampaignLabelServiceClient campaignLabelServiceClient = await CampaignLabelServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetCampaignLabelRequest request = new GetCampaignLabelRequest
            {
                ResourceNameAsCampaignLabelName = CampaignLabelName.FromCustomerCampaignLabel("[CUSTOMER]", "[CAMPAIGN_LABEL]"),
            };
            // Make the request
            CampaignLabel response = await campaignLabelServiceClient.GetCampaignLabelAsync(request);
        }
        /// <summary>Snippet for GetCampaignLabelAsync</summary>
        public async Task GetCampaignLabelAsync()
        {
            // Snippet: GetCampaignLabelAsync(string, CallSettings)
            // Additional: GetCampaignLabelAsync(string, CancellationToken)
            // Create client
            CampaignLabelServiceClient campaignLabelServiceClient = await CampaignLabelServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER]/campaignLabels/[CAMPAIGN_LABEL]";
            // Make the request
            CampaignLabel response = await campaignLabelServiceClient.GetCampaignLabelAsync(resourceName);

            // End snippet
        }
        /// <summary>Snippet for GetCampaignLabelAsync</summary>
        public async Task GetCampaignLabelResourceNamesAsync()
        {
            // Snippet: GetCampaignLabelAsync(CampaignLabelName, CallSettings)
            // Additional: GetCampaignLabelAsync(CampaignLabelName, CancellationToken)
            // Create client
            CampaignLabelServiceClient campaignLabelServiceClient = await CampaignLabelServiceClient.CreateAsync();

            // Initialize request argument(s)
            CampaignLabelName resourceName = CampaignLabelName.FromCustomerCampaignLabel("[CUSTOMER]", "[CAMPAIGN_LABEL]");
            // Make the request
            CampaignLabel response = await campaignLabelServiceClient.GetCampaignLabelAsync(resourceName);

            // End snippet
        }
示例#12
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="campaignIds">IDs of the campaigns where the campaign labels will be added.
        /// </param>
        /// <param name="labelId">The ID of the label to attach to campaigns.</param>
        public void Run(GoogleAdsClient client, long customerId, long[] campaignIds, long labelId)
        {
            // Get the CampaignLabelServiceClient.
            CampaignLabelServiceClient campaignLabelService =
                client.GetService(Services.V3.CampaignLabelService);

            // Gets the resource name of the label to be added across all given campaigns.
            string labelResourceName = ResourceNames.Label(customerId, labelId);

            List <CampaignLabelOperation> operations = new List <CampaignLabelOperation>();

            // Creates a campaign label operation for each campaign.
            foreach (long campaignId in campaignIds)
            {
                // Gets the resource name of the given campaign.
                string campaignResourceName = ResourceNames.Campaign(customerId, campaignId);
                // Creates the campaign label.
                CampaignLabel campaignLabel = new CampaignLabel()
                {
                    Campaign = campaignResourceName,
                    Label    = labelResourceName
                };

                operations.Add(new CampaignLabelOperation()
                {
                    Create = campaignLabel
                });
            }

            // Send the operation in a mutate request.
            try
            {
                MutateCampaignLabelsResponse response =
                    campaignLabelService.MutateCampaignLabels(customerId.ToString(), operations);
                Console.WriteLine($"Added {response.Results} campaign labels:");

                foreach (MutateCampaignLabelResult result in response.Results)
                {
                    Console.WriteLine(result.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>Snippet for GetCampaignLabelAsync</summary>
        public async Task GetCampaignLabelRequestObjectAsync()
        {
            // Snippet: GetCampaignLabelAsync(GetCampaignLabelRequest, CallSettings)
            // Additional: GetCampaignLabelAsync(GetCampaignLabelRequest, CancellationToken)
            // Create client
            CampaignLabelServiceClient campaignLabelServiceClient = await CampaignLabelServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetCampaignLabelRequest request = new GetCampaignLabelRequest
            {
                ResourceNameAsCampaignLabelName = CampaignLabelName.FromCustomerCampaignLabel("[CUSTOMER_ID]", "[CAMPAIGN_ID]", "[LABEL_ID]"),
            };
            // Make the request
            CampaignLabel response = await campaignLabelServiceClient.GetCampaignLabelAsync(request);

            // End snippet
        }
        public void GetCampaignLabel2()
        {
            Mock <CampaignLabelService.CampaignLabelServiceClient> mockGrpcClient = new Mock <CampaignLabelService.CampaignLabelServiceClient>(MockBehavior.Strict);
            GetCampaignLabelRequest request = new GetCampaignLabelRequest
            {
                ResourceName = new CampaignLabelName("[CUSTOMER]", "[CAMPAIGN_LABEL]").ToString(),
            };
            CampaignLabel expectedResponse = new CampaignLabel
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetCampaignLabel(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            CampaignLabelServiceClient client = new CampaignLabelServiceClientImpl(mockGrpcClient.Object, null);
            CampaignLabel response            = client.GetCampaignLabel(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public async Task GetCampaignLabelAsync2()
        {
            Mock <CampaignLabelService.CampaignLabelServiceClient> mockGrpcClient = new Mock <CampaignLabelService.CampaignLabelServiceClient>(MockBehavior.Strict);
            GetCampaignLabelRequest request = new GetCampaignLabelRequest
            {
                ResourceName = new CampaignLabelName("[CUSTOMER]", "[CAMPAIGN_LABEL]").ToString(),
            };
            CampaignLabel expectedResponse = new CampaignLabel
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetCampaignLabelAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <CampaignLabel>(Task.FromResult(expectedResponse), null, null, null, null));
            CampaignLabelServiceClient client = new CampaignLabelServiceClientImpl(mockGrpcClient.Object, null);
            CampaignLabel response            = await client.GetCampaignLabelAsync(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
    /// <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);
      }
    }