Class GoogleAdsClient.Builder

java.lang.Object
com.google.ads.googleads.lib.GoogleAdsClient.Builder
Enclosing class:
GoogleAdsClient

public abstract static class GoogleAdsClient.Builder extends Object
Builder for configuring and creating an instance of GoogleAdsClient.

Unlike GoogleAdsClient, builders are not thread safe.

  • Field Details

    • DEFAULT_PROPERTIES_CONFIG_FILE_NAME

      public static final String DEFAULT_PROPERTIES_CONFIG_FILE_NAME
      The default file name for the properties configuration file. This does not include a path.
      See Also:
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • 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. Use UserCredentials.newBuilder() or ServiceAccountCredentials.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.

    • enableApplicationDefaultCredentials

      public GoogleAdsClient.Builder enableApplicationDefaultCredentials()
    • getDeveloperToken

      public abstract String getDeveloperToken()
      Returns the developer token currently configured.
    • setDeveloperToken

      public abstract GoogleAdsClient.Builder setDeveloperToken(String developerToken)
      Sets the developer token used to obtain access to the Google Ads API.
    • isUseCloudOrgForApiAccess

      public abstract boolean isUseCloudOrgForApiAccess()
      Gets whether to use the Google Cloud Organization of your Google Cloud project instead of developer token to determine your Google Ads API access level.
    • setUseCloudOrgForApiAccess

      public abstract GoogleAdsClient.Builder setUseCloudOrgForApiAccess(boolean useCloudOrgForApiAccess)
      Specifies whether to use the Google Cloud Organization of your Google Cloud project instead of developer token to determine your Google Ads API access level.
    • getLoginCustomerId

      public abstract Long getLoginCustomerId()
      Returns the login customer ID currently configured.
    • getLinkedCustomerId

      public abstract Long getLinkedCustomerId()
      Returns the linked customer ID currently configured.
    • setLinkedCustomerId

      public abstract GoogleAdsClient.Builder setLinkedCustomerId(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(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.

    • getMaxInboundMessageBytes

      public abstract Integer getMaxInboundMessageBytes()
    • setMaxInboundMessageBytes

      public abstract GoogleAdsClient.Builder setMaxInboundMessageBytes(Integer maxInboundMessageSize)
    • setMaxInboundMessageBytes

      public void setMaxInboundMessageBytes(Properties properties)
    • getEndpoint

      public abstract String getEndpoint()
      Returns the endpoint currently configured.
    • setEndpoint

      public abstract GoogleAdsClient.Builder setEndpoint(String endpoint)
      Optional: Overrides the default endpoint. For the default value see GoogleAdsClient.DEFAULT_ENDPOINT.
    • fromPropertiesFile

      public GoogleAdsClient.Builder fromPropertiesFile() throws IOException
      Loads the Google Ads Client configuration file from the default location: "ads.properties".
      Throws:
      FileNotFoundException - if the file does not exist.
      IOException - if the file exists, but a failure occurs when trying to load properties from the file.
    • fromPropertiesFile

      public GoogleAdsClient.Builder fromPropertiesFile(File propertiesFile) throws 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.ConfigPropertyKey for the list of expected keys.

      Throws:
      FileNotFoundException - if the specified file does not exist.
      IOException - if the file exists, but a failure occurs when trying to load properties from the file.
    • fromProperties

      public GoogleAdsClient.Builder fromProperties(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.ConfigPropertyKey for the list of expected keys.

      Throws:
      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 of GoogleAdsClient based on the attributes of this builder.