I am loging with a Google Account and get MCC Account and SubAccounts, firts I get Customers Id and then I need to call another service to get Accounts name but I catch the next error:
public static List<String> GetAllCustomersId(GoogleAdsClient googleAdsClient) {
List<String> customerLst = new ArrayList<String>();
try (CustomerServiceClient customerServiceClient = googleAdsClient.getCustomerServiceClient()) {
ListAccessibleCustomersRequest request = ListAccessibleCustomersRequest.newBuilder().build();
ListAccessibleCustomersResponse response = customerServiceClient.listAccessibleCustomers(request);
for (String custResource : customerServiceClient.listAccessibleCustomers(request).getResourceNamesList()) {
custResource = custResource.substring(custResource.lastIndexOf("/") + 1, custResource.length());
/* Get tree customers*/
String query = "SELECT
customer.id, customer.descriptive_name, customer_client.resource_name, "
+ "customer_client.client_customer, customer_client.level, "
+ "customer_client.hidden FROM customer_client";
try (GoogleAdsServiceClient client = googleAdsClient.getGoogleAdsServiceClient()) {
SearchPagedResponse response1 = client.search(String.valueOf(custResource), query);
for (GoogleAdsRow row : response1.iterateAll()) {
String clientCus = row.getCustomerClient().getClientCustomer().getValue();
clientCus = clientCus.substring(clientCus.lastIndexOf("/") + 1, clientCus.length());
System.out.println("Data: " + clientCus);
String accountNameStr = GetAccountName(googleAdsClient, Long.parseLong(clientCus));
System.out.println("subaccount: " + accountNameStr);
}
}
/**/
}
}
return customerLst;
}
public static String GetAccountName(GoogleAdsClient googleAdsClient, long customerId) {
String accountNameStr = "";
try (CustomerServiceClient customerServiceClient = googleAdsClient.getCustomerServiceClient()) {
String customerResourceName = ResourceNames.customer(customerId);
Customer customer = customerServiceClient.getCustomer(customerResourceName);
// Print account information.
System.out.printf(
"Customer with ID %d, descriptive name '%s', currency code '%s', timezone '%s', "
+ "tracking URL template '%s' and auto tagging enabled '%s' was retrieved.%n",
customer.getId().getValue(), customer.getDescriptiveName().getValue(),
customer.getCurrencyCode().getValue(), customer.getTimeZone().getValue(),
customer.getTrackingUrlTemplate().getValue(), customer.getAutoTaggingEnabled().getValue());
accountNameStr = customer.getDescriptiveName().getValue();
}
return accountNameStr;
}