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({
developer_token => "INSERT_DEVELOPER_TOKEN_HERE",
login_customer_id => "INSERT_LOGIN_CUSTOMER_ID_HERE"
});
您甚至可以在執行個體化後修改設定:
$api_client->set_login_customer_id("INSERT_LOGIN_CUSTOMER_ID_HERE");
您也可以從 API Client
取得 OAuth2ApplicationsHandler 物件,並在執行階段變更用戶端 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");
設定環境變數
將用戶端執行個體化時,您可以透過環境變數進行一些配置設定 (請參閱完整清單)。
用戶端模組提供 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 用戶端中的欄位:
developer_token
:用來存取 API 的開發人員權杖。login_customer_id
:請參閱 login-customer-id 說明文件。proxy
:用於網際網路連線的 Proxy 伺服器網址。