/// <summary>Snippet for ApplyRecommendation</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void ApplyRecommendation()
 {
     // Create client
     RecommendationServiceClient recommendationServiceClient = RecommendationServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <ApplyRecommendationOperation> operations = new ApplyRecommendationOperation[]
     {
         new ApplyRecommendationOperation(),
     };
     // Make the request
     ApplyRecommendationResponse response = recommendationServiceClient.ApplyRecommendation(customerId, operations);
 }
Ejemplo n.º 2
0
 /// <summary>Snippet for ApplyRecommendation</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void ApplyRecommendationRequestObject()
 {
     // Create client
     RecommendationServiceClient recommendationServiceClient = RecommendationServiceClient.Create();
     // Initialize request argument(s)
     ApplyRecommendationRequest request = new ApplyRecommendationRequest
     {
         CustomerId = "",
         Operations =
         {
             new ApplyRecommendationOperation(),
         },
         PartialFailure = false,
     };
     // Make the request
     ApplyRecommendationResponse response = recommendationServiceClient.ApplyRecommendation(request);
 }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The customer ID for which the call is made.</param>
        /// <param name="recommendationId">ID of the recommendation to apply.</param>
        public void Run(GoogleAdsClient client, long customerId, long recommendationId)
        {
            // Get the RecommendationServiceClient.
            RecommendationServiceClient service = client.GetService(
                Services.V0.RecommendationService);

            ApplyRecommendationOperation operation = new ApplyRecommendationOperation()
            {
                ResourceName = ResourceNames.Recommendation(customerId, recommendationId),

                // Each recommendation types has optional parameters to override the recommended
                // values. For example, you can override a recommended ad when a
                // TextAdRecommendation is applied, as shown below.
                // Please read https://developers.google.com/google-ads/api/reference/rpc/google.ads.googleads.v0.services#google.ads.googleads.v0.services.ApplyRecommendationOperation
                // for details.
                // TextAd = new TextAdParameters() {
                //   Ad = new Ad() {
                //     Id = long.Parse("INSERT_AD_ID_HERE")
                //   }
                // }
            };

            bool partialFailure = false;

            try
            {
                ApplyRecommendationResponse response = service.ApplyRecommendation(
                    customerId.ToString(), partialFailure, new ApplyRecommendationOperation[] {
                    operation
                });
                Console.WriteLine($"Applied {0} recommendation(s):", response.Results.Count);
                foreach (ApplyRecommendationResult 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}");
            }
        }