Elenco account accessibili

Puoi elencare i clienti a cui puoi accedere con il ListAccessibleCustomers in CustomerService. Tuttavia, è necessario per capire quali clienti vengono restituiti in questo tipo di richiesta.

L'elenco di clienti accessibili è una delle poche richieste nell'API Search Ads 360 Reporting che non richiede la specifica di un ID cliente nella richiesta, e ignorerà qualsiasi risorsa fornita login-customer-id

L'elenco di clienti risultante si basa sulle tue credenziali OAuth. La restituisce un elenco di tutti gli account su cui puoi intervenire. direttamente tramite le tue credenziali correnti. Non sono inclusi necessariamente tutti gli account all'interno dell'account gerarchia; includerà solo gli account Se il tuo utente autenticato è stato aggiunto con diritti di amministratore o di altro tipo nell'account.

Immagina di essere l'utente A, che ricopre il ruolo di amministratore di M1 e di C3 nei due gerarchie nell'immagine in alto. Se dovessi effettuare una chiamata all'API Search Ads 360 Reporting, ad esempio per SearchAds360Service, puoi accedere alle informazioni relative agli account M1, C1, C2, e C3. Tuttavia, una chiamata a CustomerService.ListAccessibleCustomers lo farebbe restituisce solo M1 e C3 poiché questi sono gli unici account in cui l'utente A ha diretto.

Ecco un esempio di codice che illustra l'utilizzo dei 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);
    }
  }
}

Download 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()

Scarica list_Accessibility_customers.py