com.google.ads.googleads.v17.services.RecommendationServiceClient Maven / Gradle / Ivy
Show all versions of google-ads-stubs-v17 Show documentation
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.ads.googleads.v17.services;
import com.google.ads.googleads.v17.enums.AdvertisingChannelTypeEnum;
import com.google.ads.googleads.v17.enums.RecommendationTypeEnum;
import com.google.ads.googleads.v17.services.stub.RecommendationServiceStub;
import com.google.ads.googleads.v17.services.stub.RecommendationServiceStubSettings;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.rpc.UnaryCallable;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;
// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
* 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:
*
*
{@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 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:
*
*
{@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
* RecommendationServiceSettings recommendationServiceSettings =
* RecommendationServiceSettings.newBuilder()
* .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
* .build();
* RecommendationServiceClient recommendationServiceClient =
* RecommendationServiceClient.create(recommendationServiceSettings);
* }
*
* To customize the endpoint:
*
*
{@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
* 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.
*/
@Generated("by gapic-generator-java")
public class RecommendationServiceClient implements BackgroundResource {
private final RecommendationServiceSettings settings;
private final RecommendationServiceStub stub;
/** Constructs an instance of RecommendationServiceClient with default settings. */
public static final RecommendationServiceClient create() throws IOException {
return create(RecommendationServiceSettings.newBuilder().build());
}
/**
* 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.
*/
public static final RecommendationServiceClient create(RecommendationServiceSettings settings)
throws IOException {
return new RecommendationServiceClient(settings);
}
/**
* Constructs an instance of RecommendationServiceClient, using the given stub for making calls.
* This is for advanced usage - prefer using create(RecommendationServiceSettings).
*/
public static final RecommendationServiceClient create(RecommendationServiceStub stub) {
return new RecommendationServiceClient(stub);
}
/**
* 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.
*/
protected RecommendationServiceClient(RecommendationServiceSettings settings) throws IOException {
this.settings = settings;
this.stub = ((RecommendationServiceStubSettings) settings.getStubSettings()).createStub();
}
protected RecommendationServiceClient(RecommendationServiceStub stub) {
this.settings = null;
this.stub = stub;
}
public final RecommendationServiceSettings getSettings() {
return settings;
}
public RecommendationServiceStub getStub() {
return stub;
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Applies given recommendations with corresponding apply parameters.
*
*
List of thrown errors: [AuthenticationError]() [AuthorizationError]() [DatabaseError]()
* [FieldError]() [HeaderError]() [InternalError]() [MutateError]() [QuotaError]()
* [RecommendationError]() [RequestError]() [UrlFieldError]()
*
*
Sample code:
*
*
{@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 operations = new ArrayList<>();
* ApplyRecommendationResponse response =
* recommendationServiceClient.applyRecommendation(customerId, operations);
* }
* }
*
* @param customerId Required. The ID of the customer with the recommendation.
* @param 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
*/
public final ApplyRecommendationResponse applyRecommendation(
String customerId, List operations) {
ApplyRecommendationRequest request =
ApplyRecommendationRequest.newBuilder()
.setCustomerId(customerId)
.addAllOperations(operations)
.build();
return applyRecommendation(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Applies given recommendations with corresponding apply parameters.
*
* List of thrown errors: [AuthenticationError]() [AuthorizationError]() [DatabaseError]()
* [FieldError]() [HeaderError]() [InternalError]() [MutateError]() [QuotaError]()
* [RecommendationError]() [RequestError]() [UrlFieldError]()
*
*
Sample code:
*
*
{@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())
* .setPartialFailure(true)
* .build();
* ApplyRecommendationResponse response =
* recommendationServiceClient.applyRecommendation(request);
* }
* }
*
* @param 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
*/
public final ApplyRecommendationResponse applyRecommendation(ApplyRecommendationRequest request) {
return applyRecommendationCallable().call(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Applies given recommendations with corresponding apply parameters.
*
* List of thrown errors: [AuthenticationError]() [AuthorizationError]() [DatabaseError]()
* [FieldError]() [HeaderError]() [InternalError]() [MutateError]() [QuotaError]()
* [RecommendationError]() [RequestError]() [UrlFieldError]()
*
*
Sample code:
*
*
{@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())
* .setPartialFailure(true)
* .build();
* ApiFuture future =
* recommendationServiceClient.applyRecommendationCallable().futureCall(request);
* // Do something.
* ApplyRecommendationResponse response = future.get();
* }
* }
*/
public final UnaryCallable
applyRecommendationCallable() {
return stub.applyRecommendationCallable();
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Dismisses given recommendations.
*
* List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]()
* [InternalError]() [QuotaError]() [RecommendationError]() [RequestError]()
*
*
Sample code:
*
*
{@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 operations =
* new ArrayList<>();
* DismissRecommendationResponse response =
* recommendationServiceClient.dismissRecommendation(customerId, operations);
* }
* }
*
* @param customerId Required. The ID of the customer with the recommendation.
* @param 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
*/
public final DismissRecommendationResponse dismissRecommendation(
String customerId,
List operations) {
DismissRecommendationRequest request =
DismissRecommendationRequest.newBuilder()
.setCustomerId(customerId)
.addAllOperations(operations)
.build();
return dismissRecommendation(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Dismisses given recommendations.
*
* List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]()
* [InternalError]() [QuotaError]() [RecommendationError]() [RequestError]()
*
*
Sample code:
*
*
{@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())
* .setPartialFailure(true)
* .build();
* DismissRecommendationResponse response =
* recommendationServiceClient.dismissRecommendation(request);
* }
* }
*
* @param 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
*/
public final DismissRecommendationResponse dismissRecommendation(
DismissRecommendationRequest request) {
return dismissRecommendationCallable().call(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Dismisses given recommendations.
*
* List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]()
* [InternalError]() [QuotaError]() [RecommendationError]() [RequestError]()
*
*
Sample code:
*
*
{@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())
* .setPartialFailure(true)
* .build();
* ApiFuture future =
* recommendationServiceClient.dismissRecommendationCallable().futureCall(request);
* // Do something.
* DismissRecommendationResponse response = future.get();
* }
* }
*/
public final UnaryCallable
dismissRecommendationCallable() {
return stub.dismissRecommendationCallable();
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Generates Recommendations based off the requested recommendation_types.
*
* List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]()
* [InternalError]() [QuotaError]() [RecommendationError]() [RequestError]()
*
*
Sample code:
*
*
{@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 recommendationTypes = new ArrayList<>();
* AdvertisingChannelTypeEnum.AdvertisingChannelType advertisingChannelType =
* AdvertisingChannelTypeEnum.AdvertisingChannelType.forNumber(0);
* GenerateRecommendationsResponse response =
* recommendationServiceClient.generateRecommendations(
* customerId, recommendationTypes, advertisingChannelType);
* }
* }
*
* @param customerId Required. The ID of the customer generating recommendations.
* @param 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: 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
* @param 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
*/
public final GenerateRecommendationsResponse generateRecommendations(
String customerId,
List recommendationTypes,
AdvertisingChannelTypeEnum.AdvertisingChannelType advertisingChannelType) {
GenerateRecommendationsRequest request =
GenerateRecommendationsRequest.newBuilder()
.setCustomerId(customerId)
.addAllRecommendationTypes(recommendationTypes)
.setAdvertisingChannelType(advertisingChannelType)
.build();
return generateRecommendations(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Generates Recommendations based off the requested recommendation_types.
*
* List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]()
* [InternalError]() [QuotaError]() [RecommendationError]() [RequestError]()
*
*
Sample code:
*
*
{@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())
* .setCampaignSitelinkCount(1870978592)
* .setBiddingInfo(GenerateRecommendationsRequest.BiddingInfo.newBuilder().build())
* .addAllAdGroupInfo(new ArrayList())
* .setSeedInfo(GenerateRecommendationsRequest.SeedInfo.newBuilder().build())
* .build();
* GenerateRecommendationsResponse response =
* recommendationServiceClient.generateRecommendations(request);
* }
* }
*
* @param 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
*/
public final GenerateRecommendationsResponse generateRecommendations(
GenerateRecommendationsRequest request) {
return generateRecommendationsCallable().call(request);
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Generates Recommendations based off the requested recommendation_types.
*
* List of thrown errors: [AuthenticationError]() [AuthorizationError]() [HeaderError]()
* [InternalError]() [QuotaError]() [RecommendationError]() [RequestError]()
*
*
Sample code:
*
*
{@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())
* .setCampaignSitelinkCount(1870978592)
* .setBiddingInfo(GenerateRecommendationsRequest.BiddingInfo.newBuilder().build())
* .addAllAdGroupInfo(new ArrayList())
* .setSeedInfo(GenerateRecommendationsRequest.SeedInfo.newBuilder().build())
* .build();
* ApiFuture future =
* recommendationServiceClient.generateRecommendationsCallable().futureCall(request);
* // Do something.
* GenerateRecommendationsResponse response = future.get();
* }
* }
*/
public final UnaryCallable
generateRecommendationsCallable() {
return stub.generateRecommendationsCallable();
}
@Override
public final void close() {
stub.close();
}
@Override
public void shutdown() {
stub.shutdown();
}
@Override
public boolean isShutdown() {
return stub.isShutdown();
}
@Override
public boolean isTerminated() {
return stub.isTerminated();
}
@Override
public void shutdownNow() {
stub.shutdownNow();
}
@Override
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
return stub.awaitTermination(duration, unit);
}
}