アクセス可能なアカウントの一覧表示

CustomerServiceListAccessibleCustomers メソッドを使用してアクセス権を持つお客様を一覧表示できます。ただし、この種類のリクエストでどのお客様が返されるのかを理解する必要があります。

アクセス権を持つお客様を一覧表示することは、Search Ads 360 Reporting API における数少ないリクエストの一つであり、ユーザーがリクエストでお客様 ID を指定する必要はなく、指定した login-customer-id は無視されます。

お客様のリストは OAuth 認証情報に基づいて作成されます。このリクエストは、現在の認証情報を提供すると、直接操作できるすべてのアカウントのリストを返します。これには、必ずしもアカウント階層内のすべてのアカウントが含まれるわけではなく、認証されたユーザーがアカウントの管理者などの権利で追加されたアカウントだけを含みます。

ご自身が上の写真の 2 つの階層で M1C3 の管理者であるユーザー A であるとします。Search Ads 360 Reporting API に対して SearchAds360Service などの呼び出しを行う場合は、M1C1C2C3 の各アカウントの情報にアクセスできます。ただし、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 をダウンロード