Google Ads 账号有两种类型:Google Ads 经理账号和 Google Ads 广告客户账号。如需详细了解这些术语以及其他术语(例如“客户账号”和“客户”)之间的关系,请参阅账号类型。
经理账号可以管理其他 Google Ads 经理账号或 Google Ads 广告客户账号。您可以将广告客户账号与经理账号相关联,然后通过经理账号管理广告客户账号。整体关联结构是一个有向无环图,其中广告客户账号位于叶级。
您可以向单个用户或服务账号授予对 Google Ads 账号的访问权限。您可以通过以下两种方式向用户授予对广告客户账号的访问权限:
- 邀请用户加入相应广告客户账号,从而授予用户对该账号的直接访问权限。
- 邀请用户加入与相应广告客户账号相关联的经理账号,从而授予该用户对相应广告客户账号的间接访问权限。由于经理账号有权访问其下关联的所有账号,因此用户可以访问广告客户账号。
您还可以在邀请用户管理账号时分配用户角色。
请考虑以下账号层次结构。假设所有用户都具有标准访问权限。

下表总结了此账号结构。
| 用户 | 能够直接访问 | 拥有对以下内容的间接访问权限 |
|---|---|---|
| U1、SA1 | M1 | M2、A1、A2、A3 |
| U2 | M2、M3 | A1、A2、A3、A4 |
| U3 | A4 |
登录客户 ID
用户可能有权访问多个账号层次结构。在这种情况下进行 API 调用时,您需要指定要使用的根账号,以便正确确定授权和账号访问权限级别。为此,请在 API 请求中指定 login-customer-id 标头。
下表沿用了上一个示例中的账号层次结构,展示了您可以使用的登录客户 ID,以及您可以调用的相应账号列表。
| 用户 | 登录客户 ID 以使用 | 用于进行 API 调用的账号 |
|---|---|---|
| U1、SA1 | M1 | M1、M2、A1、A2、A3 |
| U2 | M2 | M2、A1、A2、A3 |
| U2 | M3 | M3、A1、A4 |
| U3 | A4 | A4 |
如果用户可以直接访问您要调用的 Google Ads 账号,则可以跳过提供 login-customer-id 标头。例如,当您使用 U3 凭据调用 A4 时,无需指定 login-customer-id 标头,因为 Google Ads 服务器可以根据客户 ID (A4) 正确确定访问权限级别。
如果您使用的是我们的某个客户端库,请使用以下设置来指定 login-customer-id 标头。
Java
将以下设置添加到 ads.properties 文件中。
api.googleads.loginCustomerId=INSERT_LOGIN_CUSTOMER_ID_HERE
C#
在初始化 GoogleAdsConfig 对象并使用该对象创建 GoogleAdsClient 对象时,添加以下设置。
GoogleAdsConfig config = new GoogleAdsConfig()
{
...
LoginCustomerId = ******
};
GoogleAdsClient client = new GoogleAdsClient(config);
PHP
将以下设置添加到 google_ads_php.ini 文件中。
[GOOGLE_ADS]
loginCustomerId = "INSERT_LOGIN_CUSTOMER_ID_HERE"
Python
将以下设置添加到 google-ads.yaml 文件中。
login_customer_id: INSERT_LOGIN_CUSTOMER_ID_HERE
Ruby
将以下设置添加到 google_ads_config.rb 文件中。
Google::Ads::GoogleAds::Config.new do |c|
c.login_customer_id = 'INSERT_LOGIN_CUSTOMER_ID_HERE'
end
通过传递此文件的保存路径来创建 GoogleAdsClient 实例。
client = Google::Ads::GoogleAds::GoogleAdsClient.new('path/to/google_ads_config.rb')
Perl
将以下设置添加到 googleads.properties 文件中。
loginCustomerId=INSERT_LOGIN_CUSTOMER_ID_HERE
curl
运行 curl 命令时,请指定以下命令行实参。
-H "login-customer-id: LOGIN_CUSTOMER_ID"
您可以使用 CustomerService.ListAccessibleCustomers 方法检索用户有直接访问权限的账号列表。这些账号可用作 login-customer-id 标头的有效值。
Java
private void runExample(GoogleAdsClient client) { // Optional: Change credentials to use a different refresh token, to retrieve customers // available for a specific user. // // UserCredentials credentials = // UserCredentials.newBuilder() // .setClientId("INSERT_OAUTH_CLIENT_ID") // .setClientSecret("INSERT_OAUTH_CLIENT_SECRET") // .setRefreshToken("INSERT_REFRESH_TOKEN") // .build(); // // client = client.toBuilder().setCredentials(credentials).build(); try (CustomerServiceClient customerService = client.getLatestVersion().createCustomerServiceClient()) { ListAccessibleCustomersResponse response = customerService.listAccessibleCustomers( ListAccessibleCustomersRequest.newBuilder().build()); System.out.printf("Total results: %d%n", response.getResourceNamesCount()); for (String customerResourceName : response.getResourceNamesList()) { System.out.printf("Customer resource name: %s%n", customerResourceName); } } }
C#
public void Run(GoogleAdsClient client) { // Get the CustomerService. CustomerServiceClient customerService = client.GetService(Services.V25.CustomerService); try { // Retrieve the list of customer resources. string[] customerResourceNames = customerService.ListAccessibleCustomers(); // Display the result. foreach (string customerResourceName in customerResourceNames) { Console.WriteLine( $"Found customer with resource name = '{customerResourceName}'."); } } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
PHP
public static function runExample(GoogleAdsClient $googleAdsClient) { $customerServiceClient = $googleAdsClient->getCustomerServiceClient(); // Issues a request for listing all accessible customers. $accessibleCustomers = $customerServiceClient->listAccessibleCustomers(new ListAccessibleCustomersRequest()); print 'Total results: ' . count($accessibleCustomers->getResourceNames()) . PHP_EOL; // Iterates over all accessible customers' resource names and prints them. foreach ($accessibleCustomers->getResourceNames() as $resourceName) { /** @var string $resourceName */ printf("Customer resource name: '%s'%s", $resourceName, PHP_EOL); } }