Search Ads 360 Reporting API เวอร์ชันใหม่พร้อมให้ใช้งานแล้ว เข้าร่วมกลุ่ม Google
searchads-api-announcements เพื่อติดตามการปรับปรุงและรุ่นที่กำลังจะเปิดตัว
แสดงรายการบัญชีที่เข้าถึงได้
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
คุณสามารถสร้างรายการลูกค้าที่มีสิทธิ์เข้าถึงได้ด้วยวิธีการ ListAccessibleCustomers
ใน CustomerService
อย่างไรก็ตาม คุณต้องเข้าใจว่าระบบจะแสดงลูกค้ารายใดในคำขอประเภทนี้
การระบุลูกค้าที่เข้าถึงได้เป็นหนึ่งในคำขอไม่กี่รายการใน Search Ads 360 Reporting API ที่ไม่ต้องระบุรหัสลูกค้าในคำขอ และจะละเว้นlogin-customer-id
ที่ระบุ
รายชื่อลูกค้าที่แสดงจะอิงตามข้อมูลเข้าสู่ระบบ OAuth ของคุณ คำขอจะแสดงรายการบัญชีทั้งหมดที่คุณดำเนินการได้โดยตรงด้วยข้อมูลเข้าสู่ระบบปัจจุบัน
การดำเนินการนี้อาจไม่รวมบัญชีทั้งหมดภายในลําดับชั้นบัญชี แต่จะมีเฉพาะบัญชีที่เพิ่มผู้ใช้ที่ตรวจสอบสิทธิ์แล้วซึ่งมีสิทธิ์ระดับผู้ดูแลระบบหรือสิทธิ์อื่นๆ ในบัญชี

สมมติว่าคุณเป็นผู้ใช้ A
ที่เป็นผู้ใช้ที่มีสิทธิ์ระดับผู้ดูแลระบบของ M1
และ C3
ในลําดับชั้น 2 ระดับที่แสดงอยู่ด้านบน หากเรียกใช้ Search Ads 360 Reporting API เช่น SearchAds360Service
คุณจะสามารถเข้าถึงข้อมูลของบัญชี M1
, C1
, C2
และ C3
แต่การเรียกไปยัง CustomerService.ListAccessibleCustomers
จะแสดงผลเฉพาะ M1
และ C3
เนื่องจากมีเพียงบัญชีเดียวที่ผู้ใช้ A
มีสิทธิ์เข้าถึงโดยตรง
ต่อไปนี้คือตัวอย่างโค้ดที่แสดงการใช้เมธอด CustomerService.ListAccessibleCustomers
Java
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package sample;
import com.google.ads.searchads360.v0.lib.SearchAds360Client;
import com.google.ads.searchads360.v0.services.CustomerServiceClient;
import com.google.ads.searchads360.v0.services.ListAccessibleCustomersRequest;
import com.google.ads.searchads360.v0.services.ListAccessibleCustomersResponse;
/** List all customers that can be accessed by the authenticated Google account. */
public class ListAccessibleCustomers {
public static void main(String[] args) {
try {
// Creates a SearchAds360Client with local properties file
final SearchAds360Client searchAds360Client =
SearchAds360Client.newBuilder().fromPropertiesFile().build();
// Creates the Customer Service Client.
CustomerServiceClient client = searchAds360Client.createCustomerServiceClient();
new ListAccessibleCustomers().runExample(client);
} catch (Exception exception) {
System.err.printf("Failed with exception: %s%n", exception);
exception.printStackTrace();
System.exit(1);
}
}
private void runExample(CustomerServiceClient customerServiceClient) {
ListAccessibleCustomersResponse response =
customerServiceClient.listAccessibleCustomers(
ListAccessibleCustomersRequest.getDefaultInstance());
System.out.printf("Total results: %d%n", response.getResourceNamesCount());
for (String customerResourceName : response.getResourceNamesList()) {
System.out.printf("Customer resource name: %s%n", customerResourceName);
}
}
}
ดาวน์โหลด ListAccessibleCustomers.java
Python
#!/usr/bin/env python
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Lists all accessible customers."""
import traceback
from util_searchads360 import SearchAds360Client
def main(client) -> None:
customer_service = client.get_customer_service()
# Issues a list accessible customer request.
accessible_customers = customer_service.list_accessible_customers()
result_total = len(accessible_customers.resource_names)
print(f"Total results: {result_total}")
resource_names = accessible_customers.resource_names
for resource_name in resource_names:
print(f'Accessible customer resource name: "{resource_name}"')
if __name__ == "__main__":
# SearchAds360Client will read the search-ads-360.yaml configuration file in
# the home directory if none is specified.
search_ads_360_client = SearchAds360Client.load_from_file()
try:
main(search_ads_360_client)
except Exception: # pylint: disable=broad-except
traceback.print_exc()
ดาวน์โหลด list_accessible_customers.py
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-29 UTC
[null,null,["อัปเดตล่าสุด 2025-08-29 UTC"],[[["\u003cp\u003eUse the \u003ccode\u003eListAccessibleCustomers\u003c/code\u003e method in \u003ccode\u003eCustomerService\u003c/code\u003e to retrieve a list of customers you can directly access.\u003c/p\u003e\n"],["\u003cp\u003eThis request uses your OAuth credentials and returns only accounts where you have admin or other direct access rights, not all accounts within the hierarchy.\u003c/p\u003e\n"],["\u003cp\u003eUnlike other Search Ads 360 Reporting API requests, this method doesn't require or consider a customer ID.\u003c/p\u003e\n"],["\u003cp\u003eYou can use the returned customer resource names to access data for those specific accounts using other API services.\u003c/p\u003e\n"]]],["The `ListAccessibleCustomers` method in `CustomerService` allows you to retrieve a list of directly accessible customer accounts. This request doesn't need a customer ID or `login-customer-id`. The returned list is determined by your OAuth credentials, showing only accounts where your user has direct administrative or other rights. Accessing information for an account in the hierarchy requires the user to have admin rights for it, while a direct call to `ListAccessibleCustomers` reveals only accounts directly managed. The document presents examples in Java and Python.\n"],null,["# List Accessible Accounts\n\nYou can list customers accessible to you with the\n[`ListAccessibleCustomers`](/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#customerservice)\nmethod in [`CustomerService`](/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#customerservice).\nHowever, it is necessary\nto understand which customers are returned in this type of request.\n\nListing accessible customers is one of the few requests in the Search Ads 360 Reporting API\nthat does not require you to specify a customer ID in the request,\nand will ignore any supplied\n[`login-customer-id`](/search-ads/reporting/concepts/call-structure#login_customer_id_header).\n\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.\nThis will not necessarily include all accounts within the account\nhierarchy; rather, it will only include accounts\nwhere your authenticated user has been added with admin or other rights\nin the account.\n\nImagine you are user `A` who is an admin for `M1` and `C3` in the two\nhierarchies\npictured above. If you were to make a call to the Search Ads 360 Reporting API, for example to\n[`SearchAds360Service`](/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#searchads360service),\nyou could access information for accounts `M1`, `C1`, `C2`,\nand `C3`. However, a call to\n[`CustomerService.ListAccessibleCustomers`](/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#customerservice) would\nreturn only `M1` and `C3` since those are the only accounts where user `A` has\n**direct** access.\n\nHere is a code example illustrating the use of the\n[`CustomerService.ListAccessibleCustomers`](/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#customerservice)\nmethod: \n\n### Java\n\n\n```java\n// Copyright 2022 Google LLC\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage sample;\n\nimport com.google.ads.searchads360.v0.lib.SearchAds360Client;\nimport com.google.ads.searchads360.v0.services.CustomerServiceClient;\nimport com.google.ads.searchads360.v0.services.ListAccessibleCustomersRequest;\nimport com.google.ads.searchads360.v0.services.ListAccessibleCustomersResponse;\n\n/** List all customers that can be accessed by the authenticated Google account. */\npublic class ListAccessibleCustomers {\n\n public static void main(String[] args) {\n try {\n // Creates a SearchAds360Client with local properties file\n final SearchAds360Client searchAds360Client =\n SearchAds360Client.newBuilder().fromPropertiesFile().build();\n // Creates the Customer Service Client.\n CustomerServiceClient client = searchAds360Client.createCustomerServiceClient();\n new ListAccessibleCustomers().runExample(client);\n } catch (Exception exception) {\n System.err.printf(\"Failed with exception: %s%n\", exception);\n exception.printStackTrace();\n System.exit(1);\n }\n }\n\n private void runExample(CustomerServiceClient customerServiceClient) {\n ListAccessibleCustomersResponse response =\n customerServiceClient.listAccessibleCustomers(\n ListAccessibleCustomersRequest.getDefaultInstance());\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}\n```\n\n\u003cbr /\u003e\n\n[Download ListAccessibleCustomers.java](https://developers.google.com/search-ads/reporting/sample-code/ListAccessibleCustomers.java)\n\n### Python\n\n\n```python\n#!/usr/bin/env python\n# Copyright 2022 Google LLC\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# https://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Lists all accessible customers.\"\"\"\n\nimport traceback\nfrom util_searchads360 import SearchAds360Client\n\n\ndef main(client) -\u003e None:\n customer_service = client.get_customer_service()\n\n # Issues a list accessible customer request.\n accessible_customers = customer_service.list_accessible_customers()\n result_total = len(accessible_customers.resource_names)\n print(f\"Total results: {result_total}\")\n\n resource_names = accessible_customers.resource_names\n for resource_name in resource_names:\n print(f'Accessible customer resource name: \"{resource_name}\"')\n\n\nif __name__ == \"__main__\":\n # SearchAds360Client will read the search-ads-360.yaml configuration file in\n # the home directory if none is specified.\n search_ads_360_client = SearchAds360Client.load_from_file()\n\n try:\n main(search_ads_360_client)\n except Exception: # pylint: disable=broad-except\n traceback.print_exc()\n```\n\n\u003cbr /\u003e\n\n[Download list_accessible_customers.py](https://developers.google.com/search-ads/reporting/sample-code/list_accessible_customers.py)"]]