設定
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
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");
設定環境變數
您可以在例項化用戶端時,從環境變數設定部分配置設定 (請參閱完整清單)。
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 用戶端中保留的欄位:
developer_token
:用於存取 API 的開發人員權杖。
login_customer_id
:請參閱登入客戶 ID 說明文件。
proxy
:用於網際網路連線的 Proxy 伺服器網址。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-27 (世界標準時間)。
[null,null,["上次更新時間:2025-08-27 (世界標準時間)。"],[[["\u003cp\u003eThe Google Ads API Client library for Perl offers flexible configuration options, including using a \u003ccode\u003egoogleads.properties\u003c/code\u003e file, dynamic settings during instantiation, or environment variables.\u003c/p\u003e\n"],["\u003cp\u003eYou can specify a \u003ccode\u003egoogleads.properties\u003c/code\u003e file to store your client ID, client secret, and refresh token for authentication, either by default in your home directory or by providing a specific file path.\u003c/p\u003e\n"],["\u003cp\u003eDynamically configure the client by setting parameters like \u003ccode\u003edeveloper_token\u003c/code\u003e and \u003ccode\u003elogin_customer_id\u003c/code\u003e during or after instantiation using provided methods.\u003c/p\u003e\n"],["\u003cp\u003eUtilize environment variables to set configuration settings, ensuring they are set beforehand, and use the \u003ccode\u003econfigure_from_environment_variables\u003c/code\u003e function to load them into the client.\u003c/p\u003e\n"],["\u003cp\u003eThe client library supports key configuration fields such as \u003ccode\u003eclient_id\u003c/code\u003e, \u003ccode\u003eclient_secret\u003c/code\u003e, \u003ccode\u003erefresh_token\u003c/code\u003e, \u003ccode\u003edeveloper_token\u003c/code\u003e, \u003ccode\u003elogin_customer_id\u003c/code\u003e, and \u003ccode\u003eproxy\u003c/code\u003e for customizing its behavior.\u003c/p\u003e\n"]]],[],null,["# Configuration\n\nAds API Client library provides several configuration settings that you can use\nto customize the library behavior.\n\nConfiguration file\n------------------\n\nYou can specify a\n[`googleads.properties`](https://github.com/googleads/google-ads-perl/blob/HEAD/googleads.properties)\nfile to use when instantiating the client.\n\nIf you use no arguments when instantiating: \n\n my $api_client = Google::Ads::GoogleAds::Client-\u003enew();\n\nthen the library will look in your `HOME` directory for the file.\n\nAlternatively, you can specify a path: \n\n my $properties_file = \"/path/to/googleads.properties\";\n\n my $api_client = Google::Ads::GoogleAds::Client-\u003enew({\n properties_file =\u003e $properties_file\n });\n\nin which case the client will look for the file at that file path.\n\nThe easiest way to generate this file is to copy the `googleads.properties` from\nthe GitHub repository and modify it to include your client ID, client secret and\nrefresh token.\n\nDynamic configuration\n---------------------\n\nYou can set up the configuration dynamically when instantiating the library, or\neven afterwards: \n\n my $api_client = Google::Ads::GoogleAds::Client-\u003enew({\n developer_token =\u003e \"INSERT_DEVELOPER_TOKEN_HERE\",\n login_customer_id =\u003e \"INSERT_LOGIN_CUSTOMER_ID_HERE\"\n });\n\nYou can even modify the configuration after instantiation: \n\n $api_client-\u003eset_login_customer_id(\"INSERT_LOGIN_CUSTOMER_ID_HERE\");\n\nYou can also get a [OAuth2ApplicationsHandler](https://github.com/googleads/google-ads-perl/blob/HEAD/lib/Google/Ads/GoogleAds/OAuth2ApplicationsHandler.pm)\nobject from the `API Client`, and change the client ID, client secret and\nrefresh token at runtime: \n\n my $oauth2_applications_handler = $api_client-\u003eget_oauth2_applications_handler();\n $oauth2_applications_handler-\u003eset_client_id(\"INSERT_CLIENT_ID\");\n $oauth2_applications_handler-\u003eset_client_secret(\"INSERT_CLIENT_SECRET\");\n $oauth2_applications_handler-\u003eset_refresh_token(\"INSERT_REFRESH_TOKEN\");\n\nConfiguration environment variables\n-----------------------------------\n\nYou can set some of the configuration settings from environment variables when\ninstantiating clients (see the [exhaustive\nlist](/google-ads/api/docs/client-libs#configuration)).\n\nThe Client module provides the `configure_from_environment_variables`\nfunction to load values from environment variables:\n**Note:** Unset environment variables are *not* taken into account. \n\n # Get the Google Ads Client. By default, any credentials will be read from\n # ~/googleads.properties, or, if set, from the file specified in the\n # GOOGLE_ADS_CONFIGURATION_FILE_PATH environment variable.\n my $api_client = Google::Ads::GoogleAds::Client-\u003enew();\n\n # Load the configuration from any set environment variables.\n $api_client-\u003econfigure_from_environment_variables();\n\nConfiguration fields\n--------------------\n\nThe configuration properties support the following fields:\n\nFields persisted in [OAuth2ApplicationsHandler](https://github.com/googleads/google-ads-perl/blob/HEAD/lib/Google/Ads/GoogleAds/OAuth2ApplicationsHandler.pm):\n\n- `client_id`: Your OAuth2 client ID.\n- `client_secret`: Your OAuth2 client secret.\n- `refresh_token`: Your OAuth2 refresh token.\n\nFields persisted in [API Client](https://github.com/googleads/google-ads-perl/blob/HEAD/lib/Google/Ads/GoogleAds/Client.pm):\n\n- `developer_token`: Your developer token for accessing the API.\n- `login_customer_id`: See the [login-customer-id documentation](/google-ads/api/docs/concepts/call-structure#cid).\n- `proxy`: The proxy server URL used for internet connectivity."]]