Edujugon / laravel-google-ads

Google Adwords API for Laravel
MIT License
68 stars 23 forks source link

usage for hiearchy accounts #42

Open gezimapi opened 5 years ago

gezimapi commented 5 years ago

hi i have to tried to list the accounts in my mcc using:

use Edujugon\GoogleAds\GoogleAds; use Google\AdsApi\AdWords\v201809\mcm\CustomerService; use Edujugon\GoogleAds\Session\AdwordsSession;

$userRefreshCredentials = [
    'clientId' => config('google-ads.production.clientId'),
    'clientSecret' => config('google-ads.production.clientSecret'),
    'refreshToken' => config('google-ads.production.refreshToken')
];

$adWordsServices = new GoogleAds(); $session = (new AdwordsSession())->buildWithOAuth(config('google-ads.production.developerToken'),$userRefreshCredentials);

$managedCustomerService = $adWordsServices->service(CustomerService::class, $session)->getService(); $page = $managedCustomerService->getCustomers();

i get this response:

Argument 1 passed to Google\AdsApi\AdWords\AdWordsSessionBuilder::withOAuth2Credential() must implement interface Google\Auth\FetchAuthTokenInterface, array given, called in /home/glanaj/projects/neon/vendor/edujugon/laravel-google-ads/src/src/Session/AdwordsSession.php on line 90

Edujugon commented 5 years ago

Hi @gezimapi ,

Make sure that your userRefreshCredentials is an instance of \Google\Auth\Credentials\UserRefreshCredentials

Edujugon commented 5 years ago

Hope this code snippet helps:

use Edujugon\GoogleAds\Auth\OAuth2;

$oAuth = new OAuth2();

$userRefreshCredentials = $oAuth->userCredentials([
    'clientId' => 'XXX',
    'clientSecret' => 'XXX',
    'refreshToken' => 'XXX'
]);
gezimapi commented 5 years ago

hi ,

Now it works , i have multiple MCC can I set the clientCustomerId to get only the accounts of one MCC.

Thx in advance