Class GoogleAdsServiceClient
- java.lang.Object
-
- com.google.ads.googleads.v10.services.GoogleAdsServiceClient
-
- All Implemented Interfaces:
com.google.api.gax.core.BackgroundResource,java.lang.AutoCloseable
@Generated("by gapic-generator-java") public class GoogleAdsServiceClient extends java.lang.Object implements com.google.api.gax.core.BackgroundResourceService Description: Service to fetch data and metrics across resources.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:
try (GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.create()) { String customerId = "customerId-1581184615"; List<MutateOperation> mutateOperations = new ArrayList<>(); MutateGoogleAdsResponse response = googleAdsServiceClient.mutate(customerId, mutateOperations); }Note: close() needs to be called on the GoogleAdsServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
- A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
- A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
- A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.
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 GoogleAdsServiceSettings to create(). For example:
To customize credentials:
GoogleAdsServiceSettings googleAdsServiceSettings = GoogleAdsServiceSettings.newBuilder() .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) .build(); GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.create(googleAdsServiceSettings);To customize the endpoint:
GoogleAdsServiceSettings googleAdsServiceSettings = GoogleAdsServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.create(googleAdsServiceSettings);Please refer to the GitHub repository's samples for more quickstart code snippets.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGoogleAdsServiceClient.SearchFixedSizeCollectionstatic classGoogleAdsServiceClient.SearchPagestatic classGoogleAdsServiceClient.SearchPagedResponse
-
Constructor Summary
Constructors Modifier Constructor Description protectedGoogleAdsServiceClient(GoogleAdsServiceSettings settings)Constructs an instance of GoogleAdsServiceClient, using the given settings.protectedGoogleAdsServiceClient(GoogleAdsServiceStub stub)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanawaitTermination(long duration, java.util.concurrent.TimeUnit unit)voidclose()static GoogleAdsServiceClientcreate()Constructs an instance of GoogleAdsServiceClient with default settings.static GoogleAdsServiceClientcreate(GoogleAdsServiceSettings settings)Constructs an instance of GoogleAdsServiceClient, using the given settings.static GoogleAdsServiceClientcreate(GoogleAdsServiceStub stub)Constructs an instance of GoogleAdsServiceClient, using the given stub for making calls.GoogleAdsServiceSettingsgetSettings()GoogleAdsServiceStubgetStub()booleanisShutdown()booleanisTerminated()MutateGoogleAdsResponsemutate(MutateGoogleAdsRequest request)Creates, updates, or removes resources.MutateGoogleAdsResponsemutate(java.lang.String customerId, java.util.List<MutateOperation> mutateOperations)Creates, updates, or removes resources.com.google.api.gax.rpc.UnaryCallable<MutateGoogleAdsRequest,MutateGoogleAdsResponse>mutateCallable()Creates, updates, or removes resources.GoogleAdsServiceClient.SearchPagedResponsesearch(SearchGoogleAdsRequest request)Returns all rows that match the search query.GoogleAdsServiceClient.SearchPagedResponsesearch(java.lang.String customerId, java.lang.String query)Returns all rows that match the search query.com.google.api.gax.rpc.UnaryCallable<SearchGoogleAdsRequest,SearchGoogleAdsResponse>searchCallable()Returns all rows that match the search query.com.google.api.gax.rpc.UnaryCallable<SearchGoogleAdsRequest,GoogleAdsServiceClient.SearchPagedResponse>searchPagedCallable()Returns all rows that match the search query.com.google.api.gax.rpc.ServerStreamingCallable<SearchGoogleAdsStreamRequest,SearchGoogleAdsStreamResponse>searchStreamCallable()Returns all rows that match the search stream query.voidshutdown()voidshutdownNow()
-
-
-
Constructor Detail
-
GoogleAdsServiceClient
protected GoogleAdsServiceClient(GoogleAdsServiceSettings settings) throws java.io.IOException
Constructs an instance of GoogleAdsServiceClient, 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:
java.io.IOException
-
GoogleAdsServiceClient
@BetaApi("A restructuring of stub classes is planned, so this may break in the future") protected GoogleAdsServiceClient(GoogleAdsServiceStub stub)
-
-
Method Detail
-
create
public static final GoogleAdsServiceClient create() throws java.io.IOException
Constructs an instance of GoogleAdsServiceClient with default settings.- Throws:
java.io.IOException
-
create
public static final GoogleAdsServiceClient create(GoogleAdsServiceSettings settings) throws java.io.IOException
Constructs an instance of GoogleAdsServiceClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.- Throws:
java.io.IOException
-
create
@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public static final GoogleAdsServiceClient create(GoogleAdsServiceStub stub)Constructs an instance of GoogleAdsServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(GoogleAdsServiceSettings).
-
getSettings
public final GoogleAdsServiceSettings getSettings()
-
getStub
@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public GoogleAdsServiceStub getStub()
-
search
public final GoogleAdsServiceClient.SearchPagedResponse search(java.lang.String customerId, java.lang.String query)
Returns all rows that match the search query.List of thrown errors: [AuthenticationError]() [AuthorizationError]() [ChangeEventError]() [ChangeStatusError]() [ClickViewError]() [HeaderError]() [InternalError]() [QueryError]() [QuotaError]() [RequestError]()
Sample code:
try (GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.create()) { String customerId = "customerId-1581184615"; String query = "query107944136"; for (GoogleAdsRow element : googleAdsServiceClient.search(customerId, query).iterateAll()) { // doThingsWith(element); } }- Parameters:
customerId- Required. The ID of the customer being queried.query- Required. The query string.- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
search
public final GoogleAdsServiceClient.SearchPagedResponse search(SearchGoogleAdsRequest request)
Returns all rows that match the search query.List of thrown errors: [AuthenticationError]() [AuthorizationError]() [ChangeEventError]() [ChangeStatusError]() [ClickViewError]() [HeaderError]() [InternalError]() [QueryError]() [QuotaError]() [RequestError]()
Sample code:
try (GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.create()) { SearchGoogleAdsRequest request = SearchGoogleAdsRequest.newBuilder() .setCustomerId("customerId-1581184615") .setQuery("query107944136") .setPageToken("pageToken873572522") .setPageSize(883849137) .setValidateOnly(true) .setReturnTotalResultsCount(true) .build(); for (GoogleAdsRow element : googleAdsServiceClient.search(request).iterateAll()) { // doThingsWith(element); } }- 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
-
searchPagedCallable
public final com.google.api.gax.rpc.UnaryCallable<SearchGoogleAdsRequest,GoogleAdsServiceClient.SearchPagedResponse> searchPagedCallable()
Returns all rows that match the search query.List of thrown errors: [AuthenticationError]() [AuthorizationError]() [ChangeEventError]() [ChangeStatusError]() [ClickViewError]() [HeaderError]() [InternalError]() [QueryError]() [QuotaError]() [RequestError]()
Sample code:
try (GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.create()) { SearchGoogleAdsRequest request = SearchGoogleAdsRequest.newBuilder() .setCustomerId("customerId-1581184615") .setQuery("query107944136") .setPageToken("pageToken873572522") .setPageSize(883849137) .setValidateOnly(true) .setReturnTotalResultsCount(true) .build(); ApiFuture<GoogleAdsRow> future = googleAdsServiceClient.searchPagedCallable().futureCall(request); // Do something. for (GoogleAdsRow element : future.get().iterateAll()) { // doThingsWith(element); } }
-
searchCallable
public final com.google.api.gax.rpc.UnaryCallable<SearchGoogleAdsRequest,SearchGoogleAdsResponse> searchCallable()
Returns all rows that match the search query.List of thrown errors: [AuthenticationError]() [AuthorizationError]() [ChangeEventError]() [ChangeStatusError]() [ClickViewError]() [HeaderError]() [InternalError]() [QueryError]() [QuotaError]() [RequestError]()
Sample code:
try (GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.create()) { SearchGoogleAdsRequest request = SearchGoogleAdsRequest.newBuilder() .setCustomerId("customerId-1581184615") .setQuery("query107944136") .setPageToken("pageToken873572522") .setPageSize(883849137) .setValidateOnly(true) .setReturnTotalResultsCount(true) .build(); while (true) { SearchGoogleAdsResponse response = googleAdsServiceClient.searchCallable().call(request); for (GoogleAdsRow element : response.getResponsesList()) { // doThingsWith(element); } String nextPageToken = response.getNextPageToken(); if (!Strings.isNullOrEmpty(nextPageToken)) { request = request.toBuilder().setPageToken(nextPageToken).build(); } else { break; } } }
-
searchStreamCallable
public final com.google.api.gax.rpc.ServerStreamingCallable<SearchGoogleAdsStreamRequest,SearchGoogleAdsStreamResponse> searchStreamCallable()
Returns all rows that match the search stream query.List of thrown errors: [AuthenticationError]() [AuthorizationError]() [ChangeEventError]() [ChangeStatusError]() [ClickViewError]() [HeaderError]() [InternalError]() [QueryError]() [QuotaError]() [RequestError]()
Sample code:
try (GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.create()) { SearchGoogleAdsStreamRequest request = SearchGoogleAdsStreamRequest.newBuilder() .setCustomerId("customerId-1581184615") .setQuery("query107944136") .build(); ServerStream<SearchGoogleAdsStreamResponse> stream = googleAdsServiceClient.searchStreamCallable().call(request); for (SearchGoogleAdsStreamResponse response : stream) { // Do something when a response is received. } }
-
mutate
public final MutateGoogleAdsResponse mutate(java.lang.String customerId, java.util.List<MutateOperation> mutateOperations)
Creates, updates, or removes resources. This method supports atomic transactions with multiple types of resources. For example, you can atomically create a campaign and a campaign budget, or perform up to thousands of mutates atomically.This method is essentially a wrapper around a series of mutate methods. The only features it offers over calling those methods directly are:
- Atomic transactions - Temp resource names (described below) - Somewhat reduced latency over making a series of mutate calls
Note: Only resources that support atomic transactions are included, so this method can't replace all calls to individual services.
## Atomic Transaction Benefits
Atomicity makes error handling much easier. If you're making a series of changes and one fails, it can leave your account in an inconsistent state. With atomicity, you either reach the desired state directly, or the request fails and you can retry.
## Temp Resource Names
Temp resource names are a special type of resource name used to create a resource and reference that resource in the same request. For example, if a campaign budget is created with `resource_name` equal to `customers/123/campaignBudgets/-1`, that resource name can be reused in the `Campaign.budget` field in the same request. That way, the two resources are created and linked atomically.
To create a temp resource name, put a negative number in the part of the name that the server would normally allocate.
Note:
- Resources must be created with a temp name before the name can be reused. For example, the previous CampaignBudget+Campaign example would fail if the mutate order was reversed. - Temp names are not remembered across requests. - There's no limit to the number of temp names in a request. - Each temp name must use a unique negative number, even if the resource types differ.
## Latency
It's important to group mutates by resource type or the request may time out and fail. Latency is roughly equal to a series of calls to individual mutate methods, where each change in resource type is a new call. For example, mutating 10 campaigns then 10 ad groups is like 2 calls, while mutating 1 campaign, 1 ad group, 1 campaign, 1 ad group is like 4 calls.
List of thrown errors: [AdCustomizerError]() [AdError]() [AdGroupAdError]() [AdGroupCriterionError]() [AdGroupError]() [AssetError]() [AuthenticationError]() [AuthorizationError]() [BiddingError]() [CampaignBudgetError]() [CampaignCriterionError]() [CampaignError]() [CampaignExperimentError]() [CampaignSharedSetError]() [CollectionSizeError]() [ContextError]() [ConversionActionError]() [CriterionError]() [CustomerFeedError]() [DatabaseError]() [DateError]() [DateRangeError]() [DistinctError]() [ExtensionFeedItemError]() [ExtensionSettingError]() [FeedAttributeReferenceError]() [FeedError]() [FeedItemError]() [FeedItemSetError]() [FieldError]() [FieldMaskError]() [FunctionParsingError]() [HeaderError]() [ImageError]() [InternalError]() [KeywordPlanAdGroupKeywordError]() [KeywordPlanCampaignError]() [KeywordPlanError]() [LabelError]() [ListOperationError]() [MediaUploadError]() [MutateError]() [NewResourceCreationError]() [NullError]() [OperationAccessDeniedError]() [PolicyFindingError]() [PolicyViolationError]() [QuotaError]() [RangeError]() [RequestError]() [ResourceCountLimitExceededError]() [SettingError]() [SharedSetError]() [SizeLimitError]() [StringFormatError]() [StringLengthError]() [UrlFieldError]() [UserListError]() [YoutubeVideoRegistrationError]()
Sample code:
try (GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.create()) { String customerId = "customerId-1581184615"; List<MutateOperation> mutateOperations = new ArrayList<>(); MutateGoogleAdsResponse response = googleAdsServiceClient.mutate(customerId, mutateOperations); }- Parameters:
customerId- Required. The ID of the customer whose resources are being modified.mutateOperations- Required. The list of operations to perform on individual resources.- Throws:
com.google.api.gax.rpc.ApiException- if the remote call fails
-
mutate
public final MutateGoogleAdsResponse mutate(MutateGoogleAdsRequest request)
Creates, updates, or removes resources. This method supports atomic transactions with multiple types of resources. For example, you can atomically create a campaign and a campaign budget, or perform up to thousands of mutates atomically.This method is essentially a wrapper around a series of mutate methods. The only features it offers over calling those methods directly are:
- Atomic transactions - Temp resource names (described below) - Somewhat reduced latency over making a series of mutate calls
Note: Only resources that support atomic transactions are included, so this method can't replace all calls to individual services.
## Atomic Transaction Benefits
Atomicity makes error handling much easier. If you're making a series of changes and one fails, it can leave your account in an inconsistent state. With atomicity, you either reach the desired state directly, or the request fails and you can retry.
## Temp Resource Names
Temp resource names are a special type of resource name used to create a resource and reference that resource in the same request. For example, if a campaign budget is created with `resource_name` equal to `customers/123/campaignBudgets/-1`, that resource name can be reused in the `Campaign.budget` field in the same request. That way, the two resources are created and linked atomically.
To create a temp resource name, put a negative number in the part of the name that the server would normally allocate.
Note:
- Resources must be created with a temp name before the name can be reused. For example, the previous CampaignBudget+Campaign example would fail if the mutate order was reversed. - Temp names are not remembered across requests. - There's no limit to the number of temp names in a request. - Each temp name must use a unique negative number, even if the resource types differ.
## Latency
It's important to group mutates by resource type or the request may time out and fail. Latency is roughly equal to a series of calls to individual mutate methods, where each change in resource type is a new call. For example, mutating 10 campaigns then 10 ad groups is like 2 calls, while mutating 1 campaign, 1 ad group, 1 campaign, 1 ad group is like 4 calls.
List of thrown errors: [AdCustomizerError]() [AdError]() [AdGroupAdError]() [AdGroupCriterionError]() [AdGroupError]() [AssetError]() [AuthenticationError]() [AuthorizationError]() [BiddingError]() [CampaignBudgetError]() [CampaignCriterionError]() [CampaignError]() [CampaignExperimentError]() [CampaignSharedSetError]() [CollectionSizeError]() [ContextError]() [ConversionActionError]() [CriterionError]() [CustomerFeedError]() [DatabaseError]() [DateError]() [DateRangeError]() [DistinctError]() [ExtensionFeedItemError]() [ExtensionSettingError]() [FeedAttributeReferenceError]() [FeedError]() [FeedItemError]() [FeedItemSetError]() [FieldError]() [FieldMaskError]() [FunctionParsingError]() [HeaderError]() [ImageError]() [InternalError]() [KeywordPlanAdGroupKeywordError]() [KeywordPlanCampaignError]() [KeywordPlanError]() [LabelError]() [ListOperationError]() [MediaUploadError]() [MutateError]() [NewResourceCreationError]() [NullError]() [OperationAccessDeniedError]() [PolicyFindingError]() [PolicyViolationError]() [QuotaError]() [RangeError]() [RequestError]() [ResourceCountLimitExceededError]() [SettingError]() [SharedSetError]() [SizeLimitError]() [StringFormatError]() [StringLengthError]() [UrlFieldError]() [UserListError]() [YoutubeVideoRegistrationError]()
Sample code:
try (GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.create()) { MutateGoogleAdsRequest request = MutateGoogleAdsRequest.newBuilder() .setCustomerId("customerId-1581184615") .addAllMutateOperations(new ArrayList<MutateOperation>()) .setPartialFailure(true) .setValidateOnly(true) .build(); MutateGoogleAdsResponse response = googleAdsServiceClient.mutate(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
-
mutateCallable
public final com.google.api.gax.rpc.UnaryCallable<MutateGoogleAdsRequest,MutateGoogleAdsResponse> mutateCallable()
Creates, updates, or removes resources. This method supports atomic transactions with multiple types of resources. For example, you can atomically create a campaign and a campaign budget, or perform up to thousands of mutates atomically.This method is essentially a wrapper around a series of mutate methods. The only features it offers over calling those methods directly are:
- Atomic transactions - Temp resource names (described below) - Somewhat reduced latency over making a series of mutate calls
Note: Only resources that support atomic transactions are included, so this method can't replace all calls to individual services.
## Atomic Transaction Benefits
Atomicity makes error handling much easier. If you're making a series of changes and one fails, it can leave your account in an inconsistent state. With atomicity, you either reach the desired state directly, or the request fails and you can retry.
## Temp Resource Names
Temp resource names are a special type of resource name used to create a resource and reference that resource in the same request. For example, if a campaign budget is created with `resource_name` equal to `customers/123/campaignBudgets/-1`, that resource name can be reused in the `Campaign.budget` field in the same request. That way, the two resources are created and linked atomically.
To create a temp resource name, put a negative number in the part of the name that the server would normally allocate.
Note:
- Resources must be created with a temp name before the name can be reused. For example, the previous CampaignBudget+Campaign example would fail if the mutate order was reversed. - Temp names are not remembered across requests. - There's no limit to the number of temp names in a request. - Each temp name must use a unique negative number, even if the resource types differ.
## Latency
It's important to group mutates by resource type or the request may time out and fail. Latency is roughly equal to a series of calls to individual mutate methods, where each change in resource type is a new call. For example, mutating 10 campaigns then 10 ad groups is like 2 calls, while mutating 1 campaign, 1 ad group, 1 campaign, 1 ad group is like 4 calls.
List of thrown errors: [AdCustomizerError]() [AdError]() [AdGroupAdError]() [AdGroupCriterionError]() [AdGroupError]() [AssetError]() [AuthenticationError]() [AuthorizationError]() [BiddingError]() [CampaignBudgetError]() [CampaignCriterionError]() [CampaignError]() [CampaignExperimentError]() [CampaignSharedSetError]() [CollectionSizeError]() [ContextError]() [ConversionActionError]() [CriterionError]() [CustomerFeedError]() [DatabaseError]() [DateError]() [DateRangeError]() [DistinctError]() [ExtensionFeedItemError]() [ExtensionSettingError]() [FeedAttributeReferenceError]() [FeedError]() [FeedItemError]() [FeedItemSetError]() [FieldError]() [FieldMaskError]() [FunctionParsingError]() [HeaderError]() [ImageError]() [InternalError]() [KeywordPlanAdGroupKeywordError]() [KeywordPlanCampaignError]() [KeywordPlanError]() [LabelError]() [ListOperationError]() [MediaUploadError]() [MutateError]() [NewResourceCreationError]() [NullError]() [OperationAccessDeniedError]() [PolicyFindingError]() [PolicyViolationError]() [QuotaError]() [RangeError]() [RequestError]() [ResourceCountLimitExceededError]() [SettingError]() [SharedSetError]() [SizeLimitError]() [StringFormatError]() [StringLengthError]() [UrlFieldError]() [UserListError]() [YoutubeVideoRegistrationError]()
Sample code:
try (GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.create()) { MutateGoogleAdsRequest request = MutateGoogleAdsRequest.newBuilder() .setCustomerId("customerId-1581184615") .addAllMutateOperations(new ArrayList<MutateOperation>()) .setPartialFailure(true) .setValidateOnly(true) .build(); ApiFuture<MutateGoogleAdsResponse> future = googleAdsServiceClient.mutateCallable().futureCall(request); // Do something. MutateGoogleAdsResponse response = future.get(); }
-
close
public final void close()
- Specified by:
closein interfacejava.lang.AutoCloseable
-
shutdown
public void shutdown()
- Specified by:
shutdownin interfacecom.google.api.gax.core.BackgroundResource
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdownin interfacecom.google.api.gax.core.BackgroundResource
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminatedin interfacecom.google.api.gax.core.BackgroundResource
-
shutdownNow
public void shutdownNow()
- Specified by:
shutdownNowin interfacecom.google.api.gax.core.BackgroundResource
-
awaitTermination
public boolean awaitTermination(long duration, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException- Specified by:
awaitTerminationin interfacecom.google.api.gax.core.BackgroundResource- Throws:
java.lang.InterruptedException
-
-