แสดงรายการบัญชีที่เข้าถึงได้

คุณสามารถระบุรายชื่อลูกค้าได้ด้วยเมธอด 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