配置
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
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
:请参阅登录客户 ID 文档。
proxy
:用于互联网连接的代理服务器网址。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-27。
[null,null,["最后更新时间 (UTC):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."]]