$user = $this->user;
//Reset to the main MCC
$user->SetClientCustomerId(AWHelper::$MASTER_CLIENT_ID);
// Get the service, which loads the required classes.
$managedCustomerService =
$user->GetService('ManagedCustomerService', AWHelper::$ADWORDS_VERSION);
// Create selector.
$selector = new Selector();
// Specify the fields to retrieve.
$selector->fields = array('AccountLabels','CustomerId', 'Name', 'CanManageClients', 'CurrencyCode');
$predicate = new Predicate();
$predicate->field = 'AccountLabels';
$predicate->operator = 'CONTAINS_ANY';
$predicate->values = array($labelName);
$selector->predicates = array($predicate);
// Make the get request.
$graph = $managedCustomerService->get($selector);
// Display serviced account graph.
if (isset($graph->entries)) {
$accounts = array();
foreach ($graph->entries as $account) {
//Only include non-manager accounts
if (!$account->canManageClients) {
$accounts[$account->customerId] = $account;
}
}
return $accounts;
} else {
return null;
}