Hello,
I think you need to follow this steps
1) You need to prepare Adwords Session without ->withClientCustomerId(
$clientCustomerId)
2) You need to use customer service to get all customers
3) Check for canManageClients field, if that is yes you need to call manage
customer service (You can use example GetAccountHierarchy )
and if not you can see customer details within the object return
here you can find the clientCustomerId as
$cliendData = $customerService->getCustomers();
$clientCustomerId = $cliendData[0]->customerId;
so Now you can prepare adwords session again to pull the campaign details,
$session = (new AdWordsSessionBuilder())
->withClientCustomerId($clientCustomerId)
->withOAuth2Credential($oAuth2Credential)
->build();
Hope this helps.
Thanks
On Tuesday, 17 January 2017 15:11:49 UTC+5:30, Minas Gratas wrote:
>
> So no one can help to get clientCustomerId with the updated library?
> If I use the code below I get no error but no clientCustomerId as well.
>
> $managedCustomerService = $adWordsServices->get( $session,
> ManagedCustomerService::class);
>
>
> On Monday, 16 January 2017 13:05:22 UTC, Minas Gratas wrote:
>>
>>
>> Hi there,
>>
>> After having loads of suggestions from you guys I solved my problems.
>> However there is one thing left.
>> Before I begin I will add my code here so anyone can see and get an idea.
>>
>> Please note; I am trying to avoid using .ini file and create this as user
>> authenticates with the application. I am getting my RefreshToken then I am
>> trying to get the ClientCustomerId to be able to fetch the campaigns.
>>
>> require 'vendor/autoload.php';
>> use Google\AdsApi\AdWords\AdWordsServices;
>> use Google\AdsApi\AdWords\AdWordsSessionBuilder;
>> use Google\AdsApi\AdWords\v201609\cm\CampaignService;
>> use Google\AdsApi\AdWords\v201609\cm\OrderBy;
>> use Google\AdsApi\AdWords\v201609\cm\Paging;
>> use Google\AdsApi\AdWords\v201609\cm\Selector;
>> use Google\AdsApi\Common\OAuth2TokenBuilder;
>> use Google\AdsApi\AdWords\v201609\mcm\CustomerService;
>> session_start();
>> $clientId = "*****";
>> $clientSecret = "****";
>> if(isset($_SESSION['refreshToken'])){
>> $refreshToken = $_SESSION['refreshToken'];
>> }else{
>> $refreshToken = NULL;
>> }
>>
>>
>> $oAuth2Credential = (new OAuth2TokenBuilder())
>> ->withClientId($clientId)
>> ->withClientSecret($clientSecret)
>> ->withRefreshToken($refreshToken)
>> ->build();
>>
>>
>> The trick was removing ->fromFile() and adding withClientId,
>> withClientSecret and withRefreshToken.
>>
>> All good now! The last missing puzzle is how to optain ClientCustomerId.
>>
>> $session = (new AdWordsSessionBuilder())
>> ->withClientCustomerId($clientCustomerId)
>> ->withOAuth2Credential($oAuth2Credential)
>> ->build();
>>
>>
>> I tried to get it like this;
>>
>> $customerService = new CustomerService();
>> $cliendData = $customerService->getCustomers();
>>
>>
>> *However I am facing with the following error.*
>> *Fatal error: Call to a member function generateHttpHeaders() on null in
>> /vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/AdsSoapClient.php
>>
>> on line 86*
>>
>> Can you put me in a right direction? Because as far as I understand from
>> the docs here
>> <https://developers.google.com/adwords/api/docs/reference/v201609/CustomerService#getcustomers>
>>
>> getCustomers does not require any parameters.
>>
>
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/11074f93-6376-4a07-874e-2d1fb9f1a79d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.