액세스 가능한 계정 나열

CustomerServiceListAccessibleCustomers 메서드를 사용하여 액세스 가능한 고객을 나열할 수 있습니다. 그러나 이 유형의 요청에서 어떤 고객이 반환되는지 파악해야 합니다.

액세스 가능한 고객을 나열하는 것은 Search Ads 360 Reporting API의 몇 가지 요청 중 하나로, 요청에 고객 ID를 지정할 필요가 없으며 제공된 login-customer-id는 무시합니다.

결과로 표시되는 고객 목록은 OAuth 사용자 인증 정보를 기반으로 합니다. 이 요청은 현재 사용자 인증 정보가 주어지면 직접 조치를 취할 수 있는 모든 계정의 목록을 반환합니다. 여기에는 계정 계층 구조 내의 모든 계정이 포함되는 것은 아니며, 인증된 사용자가 계정의 관리자 또는 기타 권한으로 추가된 계정만 포함됩니다.

위의 두 계층 구조에서 M1C3의 관리자인 A 사용자라고 가정해 보겠습니다. Search Ads 360 Reporting API를 호출하려면(예: SearchAds360Service) M1, C1, C2, C3 계정의 정보에 액세스할 수 있습니다. 그러나 CustomerService.ListAccessibleCustomers를 호출하면 M1C3만 반환됩니다. 사용자 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_access_customers.py 다운로드