فهرست حساب های قابل دسترسی
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
میتوانید مشتریانی را که در دسترس شما هستند با روش ListAccessibleCustomers
در CustomerService
فهرست کنید. با این حال، باید درک کرد که چه مشتریانی در این نوع درخواست بازگردانده می شوند.
فهرست کردن مشتریان قابل دسترسی یکی از معدود درخواستهایی در Google Ads API است که نیازی به مشخص کردن شناسه مشتری در درخواست ندارد و این درخواست هرگونه login-customer-id
ارائه شده را نادیده میگیرد. لیست مشتریان حاصل بر اساس اعتبارنامه OAuth شما است. این درخواست فهرستی از تمام حسابهایی را که میتوانید با توجه به اعتبار فعلیتان مستقیماً روی آنها عمل کنید، بازمیگرداند. این لزوماً شامل همه حسابهای موجود در سلسله مراتب حساب نمیشود. بلکه فقط شامل حسابهایی میشود که کاربر تأیید شده شما با ادمین یا سایر حقوق در حساب اضافه شده است.

تصور کنید کاربر A
هستید که ادمین M1
و C3
در دو سلسله مراتب نشان داده شده در شکل است. اگر میخواهید با Google Ads API تماس بگیرید، برای مثال با GoogleAdsService
، میتوانید به اطلاعات حسابهای M1
، C1
، C2
و C3
دسترسی داشته باشید. با این حال، تماس با CustomerService.ListAccessibleCustomers
فقط M1
و C3
را برمی گرداند زیرا این حساب ها تنها حساب هایی هستند که کاربر A
دسترسی مستقیم دارد.
در اینجا یک نمونه کد نشان دهنده استفاده از روش CustomerService.ListAccessibleCustomers
است:
جاوا
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);
}
}
}
سی شارپ
public void Run(GoogleAdsClient client)
{
// Get the CustomerService.
CustomerServiceClient customerService = client.GetService(Services.V21.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);
}
}
پایتون
def main(client: GoogleAdsClient) -> None:
customer_service: CustomerServiceClient = client.get_service(
"CustomerService"
)
accessible_customers: ListAccessibleCustomersResponse = (
customer_service.list_accessible_customers()
)
result_total: int = len(accessible_customers.resource_names)
print(f"Total results: {result_total}")
resource_names: List[str] = accessible_customers.resource_names
for resource_name in resource_names: # resource_name is implicitly str
print(f'Customer resource name: "{resource_name}"')
روبی
def list_accessible_customers()
# GoogleAdsClient will read a config file from
# ENV['HOME']/google_ads_config.rb when called without parameters
client = Google::Ads::GoogleAds::GoogleAdsClient.new
accessible_customers = client.service.customer.list_accessible_customers().resource_names
accessible_customers.each do |resource_name|
puts "Customer resource name: #{resource_name}"
end
end
پرل
sub list_accessible_customers {
my ($api_client) = @_;
my $list_accessible_customers_response =
$api_client->CustomerService()->list_accessible_customers();
printf "Total results: %d.\n",
scalar @{$list_accessible_customers_response->{resourceNames}};
foreach
my $resource_name (@{$list_accessible_customers_response->{resourceNames}})
{
printf "Customer resource name: '%s'.\n", $resource_name;
}
return 1;
}
حلقه کردن
# Returns the resource names of customers directly accessible by the user
# authenticating the call.
#
# Variables:
# API_VERSION,
# DEVELOPER_TOKEN,
# OAUTH2_ACCESS_TOKEN:
# See https://developers.google.com/google-ads/api/rest/auth#request_headers
# for details.
#
curl -f --request GET \
"https://googleads.googleapis.com/v${API_VERSION}/customers:listAccessibleCustomers" \
--header "Content-Type: application/json" \
--header "developer-token: ${DEVELOPER_TOKEN}" \
--header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \
فهرست حساب های لغو شده
Google Ads API راه مستقیمی برای فهرست کردن حسابهای لغو شده در حساب مدیر ارائه نمیکند. با این حال، می توانید از راه حل زیر برای بازیابی این لیست استفاده کنید.
لیست پیوندهای ACTIVE
را با استفاده از منبع customer_client_link
بازیابی کنید و با استفاده از قسمت customer_client_link.client_customer
فهرستی از مشتریان ایجاد کنید.
SELECT customer_client_link.client_customer, customer_client_link.status FROM
customer_client_link WHERE customer_client_link.status = ACTIVE
با استفاده از منبع customer_client
لیست حساب های ENABLED
را بازیابی کنید.
SELECT customer_client.id, customer_client.descriptive_name FROM customer_client
تفاوت بین این دو لیست لیستی از حساب های لغو شده را به شما می دهد.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThe \u003ccode\u003eListAccessibleCustomers\u003c/code\u003e method allows you to retrieve a list of customer accounts that you have direct access to with your current credentials.\u003c/p\u003e\n"],["\u003cp\u003eThis list is determined by your OAuth credentials and includes accounts where you have admin or other rights, not necessarily all accounts within the hierarchy.\u003c/p\u003e\n"],["\u003cp\u003eDirect access, as opposed to access through a manager account, is required for a customer account to be included in the results of \u003ccode\u003eListAccessibleCustomers\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eWhile the API doesn't directly list cancelled accounts, a workaround involves comparing active customer client links with enabled customer clients.\u003c/p\u003e\n"]]],[],null,["# List Accessible Accounts\n\nYou can list customers accessible to you with the\n[`ListAccessibleCustomers`](/google-ads/api/reference/rpc/v21/CustomerService/ListAccessibleCustomers)\nmethod in [`CustomerService`](/google-ads/api/reference/rpc/v21/CustomerService). However, it is\nnecessary to understand which customers are returned in this type of request.\n\nListing accessible customers is one of the few requests in the Google Ads API that does\nnot require you to specify a customer ID in the request, and the request ignores\nany supplied [`login-customer-id`](/google-ads/api/docs/concepts/call-structure#cid).\nThe resulting list of customers is based on your OAuth credentials. The\nrequest returns a list of all accounts that you are able to act upon\n**directly** given your current credentials. This won't necessarily include\nall accounts within the account hierarchy; rather, it will only include accounts\nwhere your authenticated user has been added with admin or other rights in the\naccount.\n\nImagine you are user `A` who is an admin for `M1` and `C3` in the two\nhierarchies shown in the figure. If you were to make a call to the Google Ads API, for\nexample to [`GoogleAdsService`](/google-ads/api/reference/rpc/v21/GoogleAdsService), you could\naccess information for accounts `M1`, `C1`, `C2`, and `C3`. However, a call to\n[`CustomerService.ListAccessibleCustomers`](/google-ads/api/reference/rpc/v21/CustomerService/ListAccessibleCustomers)\nwould return only `M1` and `C3` since those are the only accounts where user `A`\nhas **direct** access.\n\nHere is a code example illustrating the use of the\n[`CustomerService.ListAccessibleCustomers`](/google-ads/api/reference/rpc/v21/CustomerService/ListAccessibleCustomers)\nmethod:\n\n\n### Java\n\n```java\nprivate void runExample(GoogleAdsClient client) {\n // Optional: Change credentials to use a different refresh token, to retrieve customers\n // available for a specific user.\n //\n // UserCredentials credentials =\n // UserCredentials.newBuilder()\n // .setClientId(\"INSERT_OAUTH_CLIENT_ID\")\n // .setClientSecret(\"INSERT_OAUTH_CLIENT_SECRET\")\n // .setRefreshToken(\"INSERT_REFRESH_TOKEN\")\n // .build();\n //\n // client = client.toBuilder().setCredentials(credentials).build();\n\n try (CustomerServiceClient customerService =\n client.getLatestVersion().createCustomerServiceClient()) {\n ListAccessibleCustomersResponse response =\n customerService.listAccessibleCustomers(\n ListAccessibleCustomersRequest.newBuilder().build());\n\n System.out.printf(\"Total results: %d%n\", response.getResourceNamesCount());\n\n for (String customerResourceName : response.getResourceNamesList()) {\n System.out.printf(\"Customer resource name: %s%n\", customerResourceName);\n }\n }\n}https://github.com/googleads/google-ads-java/blob/3c3c1041c2a0ab81553e3b2a79876256649397ed/google-ads-examples/src/main/java/com/google/ads/googleads/examples/accountmanagement/ListAccessibleCustomers.java#L71-L96\n \n```\n\n### C#\n\n```c#\npublic void Run(GoogleAdsClient client)\n{\n // Get the CustomerService.\n CustomerServiceClient customerService = client.GetService(Services.V21.CustomerService);\n\n try\n {\n // Retrieve the list of customer resources.\n string[] customerResourceNames = customerService.ListAccessibleCustomers();\n\n // Display the result.\n foreach (string customerResourceName in customerResourceNames)\n {\n Console.WriteLine(\n $\"Found customer with resource name = '{customerResourceName}'.\");\n }\n }\n catch (GoogleAdsException e)\n {\n Console.WriteLine(\"Failure:\");\n Console.WriteLine($\"Message: {e.Message}\");\n Console.WriteLine($\"Failure: {e.Failure}\");\n Console.WriteLine($\"Request ID: {e.RequestId}\");\n throw;\n }\n}https://github.com/googleads/google-ads-dotnet/blob/ada966e1983b655e82172b6c3e7d9b091b522377/Google.Ads.GoogleAds/examples/AccountManagement/ListAccessibleCustomers.cs#L70-L95\n \n```\n\n### PHP\n\n```php\npublic static function runExample(GoogleAdsClient $googleAdsClient)\n{\n $customerServiceClient = $googleAdsClient-\u003egetCustomerServiceClient();\n\n // Issues a request for listing all accessible customers.\n $accessibleCustomers =\n $customerServiceClient-\u003elistAccessibleCustomers(new ListAccessibleCustomersRequest());\n print 'Total results: ' . count($accessibleCustomers-\u003egetResourceNames()) . PHP_EOL;\n\n // Iterates over all accessible customers' resource names and prints them.\n foreach ($accessibleCustomers-\u003egetResourceNames() as $resourceName) {\n /** @var string $resourceName */\n printf(\"Customer resource name: '%s'%s\", $resourceName, PHP_EOL);\n }\n} \nhttps://github.com/googleads/google-ads-php/blob/be0249c30c27b4760387bec6682b82c9f4167761/examples/AccountManagement/ListAccessibleCustomers.php#L88-L102\n\n \n```\n\n### Python\n\n```python\ndef main(client: GoogleAdsClient) -\u003e None:\n customer_service: CustomerServiceClient = client.get_service(\n \"CustomerService\"\n )\n\n accessible_customers: ListAccessibleCustomersResponse = (\n customer_service.list_accessible_customers()\n )\n result_total: int = len(accessible_customers.resource_names)\n print(f\"Total results: {result_total}\")\n\n resource_names: List[str] = accessible_customers.resource_names\n for resource_name in resource_names: # resource_name is implicitly str\n print(f'Customer resource name: \"{resource_name}\"')https://github.com/googleads/google-ads-python/blob/d0595698b8a7de6cc00684b467462601037c9db9/examples/account_management/list_accessible_customers.py#L38-L51\n \n```\n\n### Ruby\n\n```ruby\ndef list_accessible_customers()\n # GoogleAdsClient will read a config file from\n # ENV['HOME']/google_ads_config.rb when called without parameters\n client = Google::Ads::GoogleAds::GoogleAdsClient.new\n\n accessible_customers = client.service.customer.list_accessible_customers().resource_names\n\n accessible_customers.each do |resource_name|\n puts \"Customer resource name: #{resource_name}\"\n end\nend \nhttps://github.com/googleads/google-ads-ruby/blob/2752563c7ffd15a4d2238116869f64aea3011cc3/examples/account_management/list_accessible_customers.rb#L29-L39\n\n \n```\n\n### Perl\n\n```perl\nsub list_accessible_customers {\n my ($api_client) = @_;\n\n my $list_accessible_customers_response =\n $api_client-\u003eCustomerService()-\u003elist_accessible_customers();\n\n printf \"Total results: %d.\\n\",\n scalar @{$list_accessible_customers_response-\u003e{resourceNames}};\n\n foreach\n my $resource_name (@{$list_accessible_customers_response-\u003e{resourceNames}})\n {\n printf \"Customer resource name: '%s'.\\n\", $resource_name;\n }\n\n return 1;\n}https://github.com/googleads/google-ads-perl/blob/9abffd69cd856633dfdcee5c636fe9cd0eb4b5ed/examples/account_management/list_accessible_customers.pl#L36-L52\n \n```\n\n### curl\n\n```console\n# Returns the resource names of customers directly accessible by the user\n# authenticating the call.\n#\n# Variables:\n# API_VERSION,\n# DEVELOPER_TOKEN,\n# OAUTH2_ACCESS_TOKEN:\n# See https://developers.google.com/google-ads/api/rest/auth#request_headers\n# for details.\n#\ncurl -f --request GET \\\n\"https://googleads.googleapis.com/v${API_VERSION}/customers:listAccessibleCustomers\" \\\n--header \"Content-Type: application/json\" \\\n--header \"developer-token: ${DEVELOPER_TOKEN}\" \\\n--header \"Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}\" \\ \nhttps://github.com/googleads/google-ads-rest/blob/8558f03e49805014debe9d128c71821c782624b9/list_accessible_customers.sh#L16-L30\n\n \n```\n\n\u003cbr /\u003e\n\nList cancelled accounts\n-----------------------\n\nThe Google Ads API doesn't provide a direct way to list the cancelled accounts under\na Manager account. However, you can use the following workaround to retrieve\nthis list.\n\n1. Retrieve the list of `ACTIVE` links using the `customer_client_link` resource\n and make a list of customers using the `customer_client_link.client_customer`\n field.\n\n SELECT customer_client_link.client_customer, customer_client_link.status FROM\n customer_client_link WHERE customer_client_link.status = ACTIVE\n\n2. Retrieve the list of `ENABLED` accounts using the `customer_client` resource.\n\n SELECT customer_client.id, customer_client.descriptive_name FROM customer_client\n\n3. The difference between the two lists gives you the list of cancelled accounts."]]