Class RecommendationServiceClient

java.lang.Object
com.google.ads.googleads.v18.services.RecommendationServiceClient
All Implemented Interfaces:
com.google.api.gax.core.BackgroundResource, AutoCloseable

@Generated("by gapic-generator-java") public class RecommendationServiceClient extends Object implements com.google.api.gax.core.BackgroundResource
Service Description: Service to manage recommendations.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (RecommendationServiceClient recommendationServiceClient =
     RecommendationServiceClient.create()) {
   String customerId = "customerId-1581184615";
   List<ApplyRecommendationOperation> operations = new ArrayList<>();
   ApplyRecommendationResponse response =
       recommendationServiceClient.applyRecommendation(customerId, operations);
 }
 

Note: close() needs to be called on the RecommendationServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

Methods
Method Description Method Variants

ApplyRecommendation

Applies given recommendations with corresponding apply parameters.

List of thrown errors: [AuthenticationError]() [AuthorizationError]() [DatabaseError]() [FieldError]() [HeaderError]() [InternalError]() [MutateError]() [QuotaError]() [RecommendationError]() [RequestError]() [UrlFieldError]()

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • applyRecommendation(ApplyRecommendationRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • applyRecommendation(String customerId, List<ApplyRecommendationOperation> operations)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • applyRecommendationCallable()

DismissRecommendation

Dismisses given recommendations.

List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]() [InternalError]() [QuotaError]() [RecommendationError]() [RequestError]()

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • dismissRecommendation(DismissRecommendationRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • dismissRecommendation(String customerId, List<DismissRecommendationRequest.DismissRecommendationOperation> operations)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • dismissRecommendationCallable()

GenerateRecommendations

Generates Recommendations based off the requested recommendation_types.

List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]() [InternalError]() [QuotaError]() [RecommendationError]() [RequestError]()

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • generateRecommendations(GenerateRecommendationsRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • generateRecommendations(String customerId, List<RecommendationTypeEnum.RecommendationType> recommendationTypes, AdvertisingChannelTypeEnum.AdvertisingChannelType advertisingChannelType)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • generateRecommendationsCallable()

See the individual methods for example code.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of RecommendationServiceSettings to create(). For example:

To customize credentials:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 RecommendationServiceSettings recommendationServiceSettings =
     RecommendationServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 RecommendationServiceClient recommendationServiceClient =
     RecommendationServiceClient.create(recommendationServiceSettings);
 

To customize the endpoint:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 RecommendationServiceSettings recommendationServiceSettings =
     RecommendationServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 RecommendationServiceClient recommendationServiceClient =
     RecommendationServiceClient.create(recommendationServiceSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

  • Constructor Details

    • RecommendationServiceClient

      protected RecommendationServiceClient(RecommendationServiceSettings settings) throws IOException
      Constructs an instance of RecommendationServiceClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.
      Throws:
      IOException
    • RecommendationServiceClient

      protected RecommendationServiceClient(RecommendationServiceStub stub)
  • Method Details

    • create

      public static final RecommendationServiceClient create() throws IOException
      Constructs an instance of RecommendationServiceClient with default settings.
      Throws:
      IOException
    • create

      public static final RecommendationServiceClient create(RecommendationServiceSettings settings) throws IOException
      Constructs an instance of RecommendationServiceClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.
      Throws:
      IOException
    • create

      public static final RecommendationServiceClient create(RecommendationServiceStub stub)
      Constructs an instance of RecommendationServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(RecommendationServiceSettings).
    • getSettings

      public final RecommendationServiceSettings getSettings()
    • getStub

      public RecommendationServiceStub getStub()
    • applyRecommendation

      public final ApplyRecommendationResponse applyRecommendation(String customerId, List<ApplyRecommendationOperation> operations)
      Applies given recommendations with corresponding apply parameters.

      List of thrown errors: [AuthenticationError]() [AuthorizationError]() [DatabaseError]() [FieldError]() [HeaderError]() [InternalError]() [MutateError]() [QuotaError]() [RecommendationError]() [RequestError]() [UrlFieldError]()

      Sample code:

      
       // This snippet has been automatically generated and should be regarded as a code template only.
       // It will require modifications to work:
       // - It may require correct/in-range values for request initialization.
       // - It may require specifying regional endpoints when creating the service client as shown in
       // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
       try (RecommendationServiceClient recommendationServiceClient =
           RecommendationServiceClient.create()) {
         String customerId = "customerId-1581184615";
         List<ApplyRecommendationOperation> operations = new ArrayList<>();
         ApplyRecommendationResponse response =
             recommendationServiceClient.applyRecommendation(customerId, operations);
       }
       
      Parameters:
      customerId - Required. The ID of the customer with the recommendation.
      operations - Required. The list of operations to apply recommendations. If partial_failure=false all recommendations should be of the same type There is a limit of 100 operations per request.
      Throws:
      com.google.api.gax.rpc.ApiException - if the remote call fails
    • applyRecommendation

      public final ApplyRecommendationResponse applyRecommendation(ApplyRecommendationRequest request)
      Applies given recommendations with corresponding apply parameters.

      List of thrown errors: [AuthenticationError]() [AuthorizationError]() [DatabaseError]() [FieldError]() [HeaderError]() [InternalError]() [MutateError]() [QuotaError]() [RecommendationError]() [RequestError]() [UrlFieldError]()

      Sample code:

      
       // This snippet has been automatically generated and should be regarded as a code template only.
       // It will require modifications to work:
       // - It may require correct/in-range values for request initialization.
       // - It may require specifying regional endpoints when creating the service client as shown in
       // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
       try (RecommendationServiceClient recommendationServiceClient =
           RecommendationServiceClient.create()) {
         ApplyRecommendationRequest request =
             ApplyRecommendationRequest.newBuilder()
                 .setCustomerId("customerId-1581184615")
                 .addAllOperations(new ArrayList<ApplyRecommendationOperation>())
                 .setPartialFailure(true)
                 .build();
         ApplyRecommendationResponse response =
             recommendationServiceClient.applyRecommendation(request);
       }
       
      Parameters:
      request - The request object containing all of the parameters for the API call.
      Throws:
      com.google.api.gax.rpc.ApiException - if the remote call fails
    • applyRecommendationCallable

      public final com.google.api.gax.rpc.UnaryCallable<ApplyRecommendationRequest,ApplyRecommendationResponse> applyRecommendationCallable()
      Applies given recommendations with corresponding apply parameters.

      List of thrown errors: [AuthenticationError]() [AuthorizationError]() [DatabaseError]() [FieldError]() [HeaderError]() [InternalError]() [MutateError]() [QuotaError]() [RecommendationError]() [RequestError]() [UrlFieldError]()

      Sample code:

      
       // This snippet has been automatically generated and should be regarded as a code template only.
       // It will require modifications to work:
       // - It may require correct/in-range values for request initialization.
       // - It may require specifying regional endpoints when creating the service client as shown in
       // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
       try (RecommendationServiceClient recommendationServiceClient =
           RecommendationServiceClient.create()) {
         ApplyRecommendationRequest request =
             ApplyRecommendationRequest.newBuilder()
                 .setCustomerId("customerId-1581184615")
                 .addAllOperations(new ArrayList<ApplyRecommendationOperation>())
                 .setPartialFailure(true)
                 .build();
         ApiFuture<ApplyRecommendationResponse> future =
             recommendationServiceClient.applyRecommendationCallable().futureCall(request);
         // Do something.
         ApplyRecommendationResponse response = future.get();
       }
       
    • dismissRecommendation

      public final DismissRecommendationResponse dismissRecommendation(String customerId, List<DismissRecommendationRequest.DismissRecommendationOperation> operations)
      Dismisses given recommendations.

      List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]() [InternalError]() [QuotaError]() [RecommendationError]() [RequestError]()

      Sample code:

      
       // This snippet has been automatically generated and should be regarded as a code template only.
       // It will require modifications to work:
       // - It may require correct/in-range values for request initialization.
       // - It may require specifying regional endpoints when creating the service client as shown in
       // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
       try (RecommendationServiceClient recommendationServiceClient =
           RecommendationServiceClient.create()) {
         String customerId = "customerId-1581184615";
         List<DismissRecommendationRequest.DismissRecommendationOperation> operations =
             new ArrayList<>();
         DismissRecommendationResponse response =
             recommendationServiceClient.dismissRecommendation(customerId, operations);
       }
       
      Parameters:
      customerId - Required. The ID of the customer with the recommendation.
      operations - Required. The list of operations to dismiss recommendations. If partial_failure=false all recommendations should be of the same type There is a limit of 100 operations per request.
      Throws:
      com.google.api.gax.rpc.ApiException - if the remote call fails
    • dismissRecommendation

      public final DismissRecommendationResponse dismissRecommendation(DismissRecommendationRequest request)
      Dismisses given recommendations.

      List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]() [InternalError]() [QuotaError]() [RecommendationError]() [RequestError]()

      Sample code:

      
       // This snippet has been automatically generated and should be regarded as a code template only.
       // It will require modifications to work:
       // - It may require correct/in-range values for request initialization.
       // - It may require specifying regional endpoints when creating the service client as shown in
       // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
       try (RecommendationServiceClient recommendationServiceClient =
           RecommendationServiceClient.create()) {
         DismissRecommendationRequest request =
             DismissRecommendationRequest.newBuilder()
                 .setCustomerId("customerId-1581184615")
                 .addAllOperations(
                     new ArrayList<DismissRecommendationRequest.DismissRecommendationOperation>())
                 .setPartialFailure(true)
                 .build();
         DismissRecommendationResponse response =
             recommendationServiceClient.dismissRecommendation(request);
       }
       
      Parameters:
      request - The request object containing all of the parameters for the API call.
      Throws:
      com.google.api.gax.rpc.ApiException - if the remote call fails
    • dismissRecommendationCallable

      public final com.google.api.gax.rpc.UnaryCallable<DismissRecommendationRequest,DismissRecommendationResponse> dismissRecommendationCallable()
      Dismisses given recommendations.

      List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]() [InternalError]() [QuotaError]() [RecommendationError]() [RequestError]()

      Sample code:

      
       // This snippet has been automatically generated and should be regarded as a code template only.
       // It will require modifications to work:
       // - It may require correct/in-range values for request initialization.
       // - It may require specifying regional endpoints when creating the service client as shown in
       // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
       try (RecommendationServiceClient recommendationServiceClient =
           RecommendationServiceClient.create()) {
         DismissRecommendationRequest request =
             DismissRecommendationRequest.newBuilder()
                 .setCustomerId("customerId-1581184615")
                 .addAllOperations(
                     new ArrayList<DismissRecommendationRequest.DismissRecommendationOperation>())
                 .setPartialFailure(true)
                 .build();
         ApiFuture<DismissRecommendationResponse> future =
             recommendationServiceClient.dismissRecommendationCallable().futureCall(request);
         // Do something.
         DismissRecommendationResponse response = future.get();
       }
       
    • generateRecommendations

      public final GenerateRecommendationsResponse generateRecommendations(String customerId, List<RecommendationTypeEnum.RecommendationType> recommendationTypes, AdvertisingChannelTypeEnum.AdvertisingChannelType advertisingChannelType)
      Generates Recommendations based off the requested recommendation_types.

      List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]() [InternalError]() [QuotaError]() [RecommendationError]() [RequestError]()

      Sample code:

      
       // This snippet has been automatically generated and should be regarded as a code template only.
       // It will require modifications to work:
       // - It may require correct/in-range values for request initialization.
       // - It may require specifying regional endpoints when creating the service client as shown in
       // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
       try (RecommendationServiceClient recommendationServiceClient =
           RecommendationServiceClient.create()) {
         String customerId = "customerId-1581184615";
         List<RecommendationTypeEnum.RecommendationType> recommendationTypes = new ArrayList<>();
         AdvertisingChannelTypeEnum.AdvertisingChannelType advertisingChannelType =
             AdvertisingChannelTypeEnum.AdvertisingChannelType.forNumber(0);
         GenerateRecommendationsResponse response =
             recommendationServiceClient.generateRecommendations(
                 customerId, recommendationTypes, advertisingChannelType);
       }
       
      Parameters:
      customerId - Required. The ID of the customer generating recommendations.
      recommendationTypes - Required. List of eligible recommendation_types to generate. If the uploaded criteria isn't sufficient to make a recommendation, or the campaign is already in the recommended state, no recommendation will be returned for that type. Generally, a recommendation is returned if all required fields for that recommendation_type are uploaded, but there are cases where this is still not sufficient.

      The following recommendation_types are supported for recommendation generation: CAMPAIGN_BUDGET, KEYWORD, MAXIMIZE_CLICKS_OPT_IN, MAXIMIZE_CONVERSIONS_OPT_IN, MAXIMIZE_CONVERSION_VALUE_OPT_IN, SET_TARGET_CPA, SET_TARGET_ROAS, SITELINK_ASSET, TARGET_CPA_OPT_IN, TARGET_ROAS_OPT_IN

      advertisingChannelType - Required. Advertising channel type of the campaign. The following advertising_channel_types are supported for recommendation generation: PERFORMANCE_MAX and SEARCH
      Throws:
      com.google.api.gax.rpc.ApiException - if the remote call fails
    • generateRecommendations

      public final GenerateRecommendationsResponse generateRecommendations(GenerateRecommendationsRequest request)
      Generates Recommendations based off the requested recommendation_types.

      List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]() [InternalError]() [QuotaError]() [RecommendationError]() [RequestError]()

      Sample code:

      
       // This snippet has been automatically generated and should be regarded as a code template only.
       // It will require modifications to work:
       // - It may require correct/in-range values for request initialization.
       // - It may require specifying regional endpoints when creating the service client as shown in
       // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
       try (RecommendationServiceClient recommendationServiceClient =
           RecommendationServiceClient.create()) {
         GenerateRecommendationsRequest request =
             GenerateRecommendationsRequest.newBuilder()
                 .setCustomerId("customerId-1581184615")
                 .addAllRecommendationTypes(new ArrayList<RecommendationTypeEnum.RecommendationType>())
                 .setCampaignSitelinkCount(1870978592)
                 .setBiddingInfo(GenerateRecommendationsRequest.BiddingInfo.newBuilder().build())
                 .addAllAdGroupInfo(new ArrayList<GenerateRecommendationsRequest.AdGroupInfo>())
                 .setSeedInfo(GenerateRecommendationsRequest.SeedInfo.newBuilder().build())
                 .setBudgetInfo(GenerateRecommendationsRequest.BudgetInfo.newBuilder().build())
                 .setCampaignImageAssetCount(-1767290707)
                 .setCampaignCallAssetCount(1663142382)
                 .addAllCountryCodes(new ArrayList<String>())
                 .addAllLanguageCodes(new ArrayList<String>())
                 .addAllPositiveLocationsIds(new ArrayList<Long>())
                 .addAllNegativeLocationsIds(new ArrayList<Long>())
                 .addAllAssetGroupInfo(new ArrayList<GenerateRecommendationsRequest.AssetGroupInfo>())
                 .setTargetPartnerSearchNetwork(true)
                 .setTargetContentNetwork(true)
                 .build();
         GenerateRecommendationsResponse response =
             recommendationServiceClient.generateRecommendations(request);
       }
       
      Parameters:
      request - The request object containing all of the parameters for the API call.
      Throws:
      com.google.api.gax.rpc.ApiException - if the remote call fails
    • generateRecommendationsCallable

      public final com.google.api.gax.rpc.UnaryCallable<GenerateRecommendationsRequest,GenerateRecommendationsResponse> generateRecommendationsCallable()
      Generates Recommendations based off the requested recommendation_types.

      List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]() [InternalError]() [QuotaError]() [RecommendationError]() [RequestError]()

      Sample code:

      
       // This snippet has been automatically generated and should be regarded as a code template only.
       // It will require modifications to work:
       // - It may require correct/in-range values for request initialization.
       // - It may require specifying regional endpoints when creating the service client as shown in
       // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
       try (RecommendationServiceClient recommendationServiceClient =
           RecommendationServiceClient.create()) {
         GenerateRecommendationsRequest request =
             GenerateRecommendationsRequest.newBuilder()
                 .setCustomerId("customerId-1581184615")
                 .addAllRecommendationTypes(new ArrayList<RecommendationTypeEnum.RecommendationType>())
                 .setCampaignSitelinkCount(1870978592)
                 .setBiddingInfo(GenerateRecommendationsRequest.BiddingInfo.newBuilder().build())
                 .addAllAdGroupInfo(new ArrayList<GenerateRecommendationsRequest.AdGroupInfo>())
                 .setSeedInfo(GenerateRecommendationsRequest.SeedInfo.newBuilder().build())
                 .setBudgetInfo(GenerateRecommendationsRequest.BudgetInfo.newBuilder().build())
                 .setCampaignImageAssetCount(-1767290707)
                 .setCampaignCallAssetCount(1663142382)
                 .addAllCountryCodes(new ArrayList<String>())
                 .addAllLanguageCodes(new ArrayList<String>())
                 .addAllPositiveLocationsIds(new ArrayList<Long>())
                 .addAllNegativeLocationsIds(new ArrayList<Long>())
                 .addAllAssetGroupInfo(new ArrayList<GenerateRecommendationsRequest.AssetGroupInfo>())
                 .setTargetPartnerSearchNetwork(true)
                 .setTargetContentNetwork(true)
                 .build();
         ApiFuture<GenerateRecommendationsResponse> future =
             recommendationServiceClient.generateRecommendationsCallable().futureCall(request);
         // Do something.
         GenerateRecommendationsResponse response = future.get();
       }
       
    • close

      public final void close()
      Specified by:
      close in interface AutoCloseable
    • shutdown

      public void shutdown()
      Specified by:
      shutdown in interface com.google.api.gax.core.BackgroundResource
    • isShutdown

      public boolean isShutdown()
      Specified by:
      isShutdown in interface com.google.api.gax.core.BackgroundResource
    • isTerminated

      public boolean isTerminated()
      Specified by:
      isTerminated in interface com.google.api.gax.core.BackgroundResource
    • shutdownNow

      public void shutdownNow()
      Specified by:
      shutdownNow in interface com.google.api.gax.core.BackgroundResource
    • awaitTermination

      public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
      Specified by:
      awaitTermination in interface com.google.api.gax.core.BackgroundResource
      Throws:
      InterruptedException