ClientCustomerId returns empty on AdwordsUser object

184 views
Skip to first unread message

James Andrews

unread,
Apr 24, 2017, 9:00:21 AM4/24/17
to AdWords API Forum
Last week I noticed that there was a change to the php Adwords API library.

Previously when we authenticated a user I would use:

$customerService = $this->user->GetService("CustomerService");
$customer = $customerService->get();

To get the customer associated with the user who granted us the oauth token.  According to the link below that has changed.

https://github.com/googleads/googleads-php-lib/blob/master/src/Google/AdsApi/AdWords/v201702/mcm/CustomerService.php#L83-L85

I looked around and found the GetClientCustomerId object on the AdwordsUser object.  However when I try to run it it returns as empty.  My only thought is that if I list out all the customers I only have one, which is correct, so I am wonder if this returns empty if there is only one customer associated with the account.

Any help on what I am doing wrong would be appreciated.









James Andrews

unread,
Apr 24, 2017, 9:42:25 AM4/24/17
to AdWords API Forum
I should point out that $this->user is an AdwordsUser object.

Shwetha Vastrad (AdWords API Team)

unread,
Apr 24, 2017, 11:01:02 AM4/24/17
to AdWords API Forum
Hi James, 

If you haven't set the clientCustomerId in your auth.ini file, then you'll not be able to retrieve it from the AdWordsUser object. To use the CustomerService to retrieve the AdWords account associated with the authenticated user, you need to use the getCustomers method as shown here. If the authenticated user is linked to just one AdWords account, then the response will contain the details of that customer. If a clientCustomerId is specified in the request header, only details of that customer will be returned. If no clientCustomerId is specified in a request, the response will contain multiple entries if more than one account is directly accessible by the authenticated user. 

On another note, in December 2016, we announced the stable release of the new ads PHP library and the deprecation of the old one. The new PHP library has many improvements such as support of namespaces and Composer installation. The AdwordsUser which was used to configure the AdWords settings is now replaced by the AdWordsSessionBuilder. Please see the upgrading guide for more details. 

Regards,
Shwetha, AdWords API Team.

James Andrews

unread,
Apr 24, 2017, 11:18:42 AM4/24/17
to AdWords API Forum
I hadn't seen the notice for update, so that's something I guess I need to work on.

The question is then, is there a way to get the customer information on the owner of the access token with the new api?

I'll explain why I need it.  We don't and never have used an INI file.  We pull data for many clients.  They log into our website and create what we call a "remote identity"  which is basically a collection of  tokens for various APIs (Google, Adwords, Facebook, Instagram) etc...  

Part of the primary table for remote identities we store the remote api's userId, and identifying name so when customer goes to use their remote identity on one of our products they can easily select the right one and then when they can choose what adwords "customer" they want to associate with their order from that remote identity.  If we can't get access to this data then it means our process which was written generically to accommodate all oauth APIs now needs to be hacked for the special case of adwords.

Thanks,
James

Shwetha Vastrad (AdWords API Team)

unread,
Apr 24, 2017, 2:35:28 PM4/24/17
to AdWords API Forum
Hi James, 

Assuming you have the OAuth2 credentials of the user for whom you need to retrieve the AdWords account details, you need to use CustomerService.getCustomers() method without setting the clientCustomerId header along with the credentials generated. The response will contain the details of all AdWords accounts associated with the authenticated Google account.

Please note that you'll only be able to get the AdWords account which can be directly accessible by this user. If the user has access to a manager account and you would like to retrieve the client accounts linked to this manager, you need to use ManagedCustomerService as shown in this example

James Andrews

unread,
Apr 24, 2017, 3:31:47 PM4/24/17
to AdWords API Forum
Hi Shwetha,

OK, so if I call getCustomers() with the oauth credentials the return is an array, but it sounds like you're saying that the array will only ever have 1 node and that will be the customer associated with the oauth credentials.  If that's the case then I think i am set, please confirm that is the case.

The ManagedCustomerService is what we are doing now, so glad that hasn't changed.

Thanks,
James

Shwetha Vastrad (AdWords API Team)

unread,
Apr 24, 2017, 4:17:17 PM4/24/17
to AdWords API Forum
Hi James, 

On September 12th, 2016, AdWords announced that you can now use one Google login to access multiple AdWords accounts. With this change, you can associate up to 5 AdWords accounts with a single Google account. In this scenario, the getCustomers() method will return all the AdWords accounts directly accessible by this Google account. If you have a single AdWords account associated with the OAuth2 credentials, then the response will contain the details of that account alone. 
Reply all
Reply to author
Forward
0 new messages