// 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);
}
}
}