設定

Ads API クライアント ライブラリには、ライブラリの動作をカスタマイズするために使用できる構成設定がいくつか用意されています。

構成ファイル

クライアントのインスタンス化時に使用する googleads.properties ファイルを指定できます。

インスタンス化時に引数を使用しない場合:

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

ライブラリは HOME ディレクトリでファイルを探します。

または、パスを指定することもできます。

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

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

この場合、クライアントはそのパスでファイルを探します。

このファイルを生成する最も簡単な方法は、GitHub リポジトリから googleads.properties をコピーし、クライアント ID、クライアント シークレット、更新トークンを含めるように変更することです。

動的構成

ライブラリのインスタンス化時、またはインスタンス化後に、構成を動的に設定できます。

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

インスタンス化後に構成を変更することもできます。

$api_client->set_login_customer_id("INSERT_LOGIN_CUSTOMER_ID_HERE");

OAuth2ApplicationsHandler オブジェクトを API Client から取得し、実行時にクライアント ID、クライアント シークレット、更新トークンを変更することもできます。

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");

構成環境変数

クライアントのインスタンス化時に、環境変数から構成設定の一部を設定できます(詳細なリストをご覧ください)。

Client モジュールには、環境変数から値を読み込む configure_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();

構成フィールド

構成プロパティは次のフィールドをサポートしています。

OAuth2ApplicationsHandler に保持されるフィールド:

  • client_id: OAuth2 クライアント ID。
  • client_secret: OAuth2 クライアント シークレット。
  • refresh_token: OAuth2 更新トークン。

API クライアントに保持されるフィールド: