laravel-google-ads
laravel-google-ads copied to clipboard
Get all accounts
Hi,
I'm Vergel Aranas. Currently use your package.
How to get all client/account customer Ids?
Hi,
I'm Vergel Aranas. Currently use your package.
How to get all client/account customer Ids?
Could you find a way to get all clients/accounts? Please let me know. Thanks.
Hi @ayushiindianic,
Yes, I've find a way to get all clients/accounts. Thanks for you package. It's really helpul.
@iceverge Haha that's not my package. I am also looking for a way to get all clients. If you know please share the code if possible. Thanks!
@ayushiindianic here is the code. Get all Account/Clients
` public function getAllAccounts(Request $request) { $oAuth2Credential = $this->oAuth->userCredentials([ 'clientId' => config('google-ads.production.clientId'), 'clientSecret' => config('google-ads.production.clientSecret'), 'refreshToken' => $request->refreshToken, ]);
$session = (new AdwordsSession())->buildWithOAuth(config('google-ads.production.developerToken'), $oAuth2Credential);
$managedCustomerService = (new AdWordsServices())->get($session, ManagedCustomerService::class);
$selector = (new Selector())
->setFields(['CustomerId', 'Name'])
->setOrdering([new OrderBy('CustomerId', SortOrder::ASCENDING)]);
$customers = $managedCustomerService->get($selector);
$clients = [];
foreach ($customers->getEntries() as $customer) {
$clients[] = [
'customer_name' => $customer->getName(),
'customer_id' => $customer->getCustomerId()
];
}
return response($clients);
} `