We have just started using the new google ads api version 2.2, but we are not able to get the list of Customer Clients from Customer ID. We are testing the API call for the Test MCC accounts and we are able to fetch the list of accessible customers, but the details of customer client accounts from customer id is not coming and api call returns 0. Here is the below Code
function linkAllClients($customerId, $access_token, $refresh_token) {
try {
// Generate a refreshable OAuth2 credential for authentication.
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile(config('adwords.ini_path'))->withClientId(config("adwords.client_id"))->withClientSecret(config("adwords.client_secret"))->withRefreshToken($refresh_token)->build();
// Construct a Google Ads client configured from a properties file and the
// OAuth2 credentials above.
$googleAdsClient = (new GoogleAdsClientBuilder())->fromFile(config('adwords.ini_path'))
->withLoginCustomerId($customerId)
->withOAuth2Credential($oAuth2Credential)
->build();
$googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
$query = 'SELECT
customer_client.id, customer_client.level, customer_client.client_customer, customer_client.descriptive_name, customer_client.currency_code, customer_client.time_zone, customer_client.manager FROM customer_client';
$response = $googleAdsServiceClient->search($customerId, $query, ['pageSize' => 100]);
echo iterator_count($response->iterateAllElements());
die;
foreach ($response->iterateAllElements() as $googleAdsRow) {
$customerClient = $googleAdsRow->getCustomerClient();
}
} catch (GoogleAdsException $googleAdsException) {
printf(
"Request with ID '%s' has failed.%sGoogle Ads failure details:%s",
$googleAdsException->getRequestId(),
PHP_EOL,
PHP_EOL
);
foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
/** @var GoogleAdsError $error */
printf(
"\t%s: %s%s",
$error->getErrorCode()->getErrorCode(),
$error->getMessage(),
PHP_EOL
);
}
die;
} catch (ApiException $apiException) {
printf(
"ApiException was thrown with message '%s'.%s",
$apiException->getMessage(),
PHP_EOL
);
die;
} catch (\Exception $ex) {
echo $ex->getMessage() . " : " . $ex->getFile() . " : " . $ex->getLine().PHP_EOL;
die;
}
}
The above code returns 0 for iterator_count, where as there are accounts in test mcc account.