Class GoogleAdsClient.Builder

  • Enclosing class:
    GoogleAdsClient

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

    Unlike GoogleAdsClient, builders are not thread safe.

    • 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
    • Constructor Detail

      • Builder

        public Builder()
    • 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. 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.

      • 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.
      • 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.ConfigPropertyKey for 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.ConfigPropertyKey for the list of expected keys.

        Throws:
        java.lang.IllegalArgumentException - if a failure occurs when trying to load properties from the file.