ऐक्सेस किए जा सकने वाले खातों की सूची बनाएं

CustomerService में ListAccessibleCustomers तरीके का इस्तेमाल करके, उन ग्राहकों की सूची दी जा सकती है जिन्हें ऐक्सेस किया जा सकता है. हालांकि, यह समझना ज़रूरी है कि इस तरह के अनुरोध में किन ग्राहकों को दिखाया जाता है.

ऐक्सेस किए जा सकने वाले ग्राहकों की सूची बनाना, Search Ads 360 Reporting API में उन कुछ अनुरोधों में से एक है जिसके लिए आपको ग्राहक आईडी देने की ज़रूरत नहीं होती. अगर कोई ग्राहक आईडी login-customer-id दिया जाता है, तो उसे अनदेखा कर दिया जाएगा.

ग्राहकों की जो सूची बनती है वह आपके OAuth क्रेडेंशियल के हिसाब से होती है. अनुरोध आपको उन सभी खातों की सूची दिखाता है जिन पर अपने मौजूदा क्रेडेंशियल की मदद से सीधे कार्रवाई की जा सकती है. ज़रूरी नहीं है कि इसमें खाते के क्रम में मौजूद सभी खाते शामिल हों; इसके बजाय, इसमें सिर्फ़ वे खाते शामिल होंगे जिनमें पुष्टि किए गए उपयोगकर्ता को खाते में एडमिन या अन्य अधिकारों के साथ जोड़ा गया हो.

मान लें कि आप उपयोगकर्ता A हैं, जो ऊपर दी गई दो क्रमों में M1 और C3 के लिए एडमिन है. अगर आपको 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 डाउनलोड करें