laravel-google-ads icon indicating copy to clipboard operation
laravel-google-ads copied to clipboard

Get all accounts

Open ppcvergel opened this issue 5 years ago • 4 comments

Hi,

I'm Vergel Aranas. Currently use your package.

How to get all client/account customer Ids?

ppcvergel avatar Apr 02 '20 14:04 ppcvergel

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.

ayushiindianic avatar Aug 22 '20 07:08 ayushiindianic

Hi @ayushiindianic,

Yes, I've find a way to get all clients/accounts. Thanks for you package. It's really helpul.

iceverge avatar Aug 25 '20 08:08 iceverge

@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 avatar Aug 25 '20 08:08 ayushiindianic

@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);

} `

iceverge avatar Sep 01 '20 04:09 iceverge