Class GoogleAdsClient.Builder
- java.lang.Object
-
- com.google.ads.googleads.lib.GoogleAdsClient.Builder
-
- Enclosing class:
- GoogleAdsClient
public abstract static class GoogleAdsClient.Builder extends java.lang.ObjectBuilder for configuring and creating an instance ofGoogleAdsClient.Unlike
GoogleAdsClient, builders are not thread safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGoogleAdsClient.Builder.AdsEnvironmentVariableEnumeration of the environment variables that can be used to configure aGoogleAdsClient.static classGoogleAdsClient.Builder.ConfigPropertyKeyEnum of keys expected in the "ads.properties".
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_PROPERTIES_CONFIG_FILE_NAMEThe default file name for the properties configuration file.
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description GoogleAdsClientbuild()Returns a new instance ofGoogleAdsClientbased on the attributes of this builder.GoogleAdsClient.BuilderfromEnvironment()GoogleAdsClient.BuilderfromProperties(java.util.Properties properties)Updates this builder with values set from a properties object.GoogleAdsClient.BuilderfromPropertiesFile()Loads the Google Ads Client configuration file from the default location: "ads.properties".GoogleAdsClient.BuilderfromPropertiesFile(java.io.File propertiesFile)Updates this builder with values set from a properties file.abstract com.google.auth.CredentialsgetCredentials()Returns the credentials currently configured.abstract java.lang.StringgetDeveloperToken()Returns the developer token currently configured.abstract java.lang.StringgetEndpoint()Returns the endpoint currently configured.abstract java.lang.LonggetLinkedCustomerId()Returns the linked customer ID currently configured.abstract java.lang.LonggetLoginCustomerId()Returns the login customer ID currently configured.abstract GoogleAdsClient.BuildersetCredentials(com.google.auth.Credentials credentials)Specifies the OAuth credentials.abstract GoogleAdsClient.BuildersetDeveloperToken(java.lang.String developerToken)Sets the developer token used to obtain access to the Google Ads API.abstract GoogleAdsClient.BuildersetEndpoint(java.lang.String endpoint)Optional: Overrides the default endpoint.abstract GoogleAdsClient.BuildersetLinkedCustomerId(java.lang.Long linkedCustomerId)Required by a small subset of services and use-cases.abstract GoogleAdsClient.BuildersetLoginCustomerId(java.lang.Long customerId)Required for manager accounts only.
-
-
-
Field Detail
-
DEFAULT_PROPERTIES_CONFIG_FILE_NAME
public static final java.lang.String DEFAULT_PROPERTIES_CONFIG_FILE_NAME
The default file name for the properties configuration file. This does not include a path.- See Also:
- Constant Field Values
-
-
Method Detail
-
getCredentials
public abstract com.google.auth.Credentials getCredentials()
Returns the credentials currently configured.
-
setCredentials
public abstract GoogleAdsClient.Builder setCredentials(com.google.auth.Credentials credentials)
Specifies the OAuth credentials. UseUserCredentials.newBuilder()orServiceAccountCredentials.newBuilder()to build this object, or configure your credentials using a properties file or environment variables.This field is marked nullable to facilitate testing of the client library. In practice, all requests to Google Ads API must be authenticated.
-
getDeveloperToken
public abstract java.lang.String getDeveloperToken()
Returns the developer token currently configured.
-
setDeveloperToken
public abstract GoogleAdsClient.Builder setDeveloperToken(java.lang.String developerToken)
Sets the developer token used to obtain access to the Google Ads API.
-
getLoginCustomerId
public abstract java.lang.Long getLoginCustomerId()
Returns the login customer ID currently configured.
-
getLinkedCustomerId
public abstract java.lang.Long getLinkedCustomerId()
Returns the linked customer ID currently configured.
-
setLinkedCustomerId
public abstract GoogleAdsClient.Builder setLinkedCustomerId(java.lang.Long linkedCustomerId)
Required by a small subset of services and use-cases. Only required if explicitly instructed in the service documentation.
-
setLoginCustomerId
public abstract GoogleAdsClient.Builder setLoginCustomerId(java.lang.Long customerId)
Required for manager accounts only. When authenticating as a Google Ads manager account, specifies the customer ID of the authenticating manager account.If your OAuth credentials are for a user with access to multiple manager accounts you must create a separate GoogleAdsClient instance for each manager account. Use
toBuilder().setLoginCustomerId(...).build()to change the loginCustomerId.
-
getEndpoint
public abstract java.lang.String getEndpoint()
Returns the endpoint currently configured.
-
setEndpoint
public abstract GoogleAdsClient.Builder setEndpoint(java.lang.String endpoint)
Optional: Overrides the default endpoint. For the default value seeGoogleAdsClient.DEFAULT_ENDPOINT.
-
fromPropertiesFile
public GoogleAdsClient.Builder fromPropertiesFile() throws java.io.IOException
Loads the Google Ads Client configuration file from the default location: "ads.properties".- Throws:
java.io.FileNotFoundException- if the file does not exist.java.io.IOException- if the file exists, but a failure occurs when trying to load properties from the file.
-
fromPropertiesFile
public GoogleAdsClient.Builder fromPropertiesFile(java.io.File propertiesFile) throws java.io.IOException
Updates this builder with values set from a properties file.The format is similar to the format specified in the AdWords API's client library for Java, except the property keys have changed. See
GoogleAdsClient.Builder.ConfigPropertyKeyfor the list of expected keys.- Throws:
java.io.FileNotFoundException- if the specified file does not exist.java.io.IOException- if the file exists, but a failure occurs when trying to load properties from the file.
-
fromProperties
public GoogleAdsClient.Builder fromProperties(java.util.Properties properties)
Updates this builder with values set from a properties object.The format is similar to the format specified in the AdWords API's client library for Java, except the property keys have changed. See
GoogleAdsClient.Builder.ConfigPropertyKeyfor the list of expected keys.- Throws:
java.lang.IllegalArgumentException- if a failure occurs when trying to load properties from the file.
-
fromEnvironment
public GoogleAdsClient.Builder fromEnvironment()
-
build
public GoogleAdsClient build()
Returns a new instance ofGoogleAdsClientbased on the attributes of this builder.
-
-