Learn more about migrating to the Google Ads API by watching our latest webinar

Configuration

Ads API Client library provides several configuration settings that you can use to customize the library behavior.

Configuration file

You can specify a googleads.properties file to use when instantiating the client.

If you use no arguments when instantiating:

my $api_client = Google::Ads::GoogleAds::Client->new();

then the library will look in your HOME directory for the file.

Alternatively, you can specify a path:

my $properties_file = "/path/to/googleads.properties";

my $api_client = Google::Ads::GoogleAds::Client->new({
  properties_file => $properties_file
});

in which case the client will look for the file at that file path.

The easiest way to generate this file is to copy the googleads.properties from the GitHub repository and modify it to include your client ID, client secret and refresh token.

Dynamic configuration

You can set up the configuration dynamically when instantiating the library, or even afterwards:

my $api_client = Google::Ads::GoogleAds::Client->new({
  developer_token   => "INSERT_DEVELOPER_TOKEN_HERE",
  login_customer_id => "INSERT_LOGIN_CUSTOMER_ID_HERE"
});

You can even modify the configuration after instantiation:

$api_client->set_login_customer_id("INSERT_LOGIN_CUSTOMER_ID_HERE");

You can also get a OAuth2ApplicationsHandler object from the API Client, and change the client ID, client secret and refresh token at runtime:

my $oauth2_applications_handler = $api_client->get_oauth2_applications_handler();
$oauth2_applications_handler->set_client_id("INSERT_CLIENT_ID");
$oauth2_applications_handler->set_client_secret("INSERT_CLIENT_SECRET");
$oauth2_applications_handler->set_refresh_token("INSERT_REFRESH_TOKEN");

Configuration environment variables

You can set some of the configuration settings from environment variables when instantiating clients (see the exhaustive list).

The Client module provides the configure_from_environment_variables function to load values from environment variables:

# Get the Google Ads Client. By default, any credentials will be read from
# ~/googleads.properties, or, if set, from the file specified in the
# GOOGLE_ADS_CONFIGURATION_FILE_PATH environment variable.
my $api_client = Google::Ads::GoogleAds::Client->new();

# Load the configuration from any set environment variables.
$api_client->configure_from_environment_variables();

Configuration fields

The configuration properties support the following fields:

Fields persisted in OAuth2ApplicationsHandler:

  • client_id: Your OAuth2 client ID.
  • client_secret: Your OAuth2 client secret.
  • refresh_token: Your OAuth2 refresh token.

Fields persisted in API Client:

  • developer_token: Your developer token for accessing the API.
  • login_customer_id: See the login-customer-id documentation.
  • proxy: The proxy server URL used for internet connectivity.