how to get client customer id of logged in user in js or in php

2,035 views
Skip to first unread message

revin...@gmail.com

unread,
Nov 18, 2016, 9:07:26 AM11/18/16
to AdWords API Forum
Its really important for me 

i want to fetch clientcustomerId for a loogged in user so that i can pass it in to the following code 

  $user = new AdWordsUser();
  $user->SetClientCustomerId('CLIENT_CUSTOMER_ID_HERE');


i am not sure if it is posible through js login in php

if it is possible though javascript , i ll handle that according to my requirement 

i am creating a system in which any adwords user will login and can see his campaign , ads and stats according to the that ad.

Thanks in advance .


Vishal Vinayak (Adwords API Team)

unread,
Nov 18, 2016, 4:49:48 PM11/18/16
to AdWords API Forum
Hi,

Could you please elaborate what do you mean by "logged in user"? Ideally, using the code snippet in your post (also mentioned here), you can change the client customer ID at runtime. This is assuming you already have the new client customer ID saved in your environment (variable/properties file/database etc). If you already have access to an AdWords account using the API, you can use CustomerService.getCustomers to fetch the Customer object, which would contain the customerId (i.e. the 10 digit AdWords account ID) of the user's account. 

Regards,
Vishal, AdWords API Team

revin...@gmail.com

unread,
Nov 22, 2016, 4:52:26 AM11/22/16
to AdWords API Forum
so for example 
i created a page where i have to login through google adwords credentials ,
i entered my google adwords credentials , so on that moment i want a customer id so that i can pass it in to my api
logged in user means those user which are logged in through my api, when they will login through my page in to google 
i want their customer id , to pass it to my php api , if it is possible though js  i ll strore that in to localstorage , and if it possible through any other source , then please help me finding that source..



  $user = new AdWordsUser();
  $user->SetClientCustomerId('CLIENT_CUSTOMER_ID_HERE');

revin...@gmail.com

unread,
Nov 22, 2016, 4:56:27 AM11/22/16
to AdWords API Forum
i am creating a system in which any google user can login 
and can see his/her adwords campaign and ads related stats , thatwhy i am asking that how can i get a customerId of a logged in user using js in google .

Vishal Vinayak (Adwords API Team)

unread,
Nov 22, 2016, 11:33:37 AM11/22/16
to AdWords API Forum
Hi,

AdWords API doesn't authenticate using email/username and password combination. Instead, authentication happens using OAuth2, details for which are available here. In other words, to connect an external tool to an AdWords account via the API, you need two things: a developer token (associated with a manager account) and valid OAuth credentials (which includes client ID and client secret). OAuth credentials can be created using any email address associated with the target AdWords account or the manager account of the target AdWords account. As long as this configuration is available in the external tool, the tool would be able to access the data of the target AdWords account. 

Please revert if you have more questions.

Regards,
Vishal Vinayak, AdWords API Team

revin...@gmail.com

unread,
Nov 23, 2016, 12:13:11 AM11/23/16
to AdWords API Forum
Hi Vishal ,
              i already have developer token created from a manager account , and using oauth credentials generated from a test manager account ,
as u said i can set clientCustomerId dynamically in any php file like below

  $user = new AdWordsUser();
  $user->SetClientCustomerId('CLIENT_CUSTOMER_ID_HERE');

or i can set it in auth.ini as well like below :

clientCustomerId = "INSERT_CLIENT_CUSTOMER_ID_HERE"

this can only be done if i already know the client id , i can only know the client id of mine , but what if another user wants to use my api ?
as api needs clientCustomerId to process and perform operation, what step should i follow to get clientCustomerId of a new adwords user or the others user who wants to use my api to see their campaign,ads related data?

this api will be like a system in which any user can sign in and can see the data(campaign,ads, ads statistics) related to their adwords account 

in simple words , i am creating an api system where not only i can sign in and see campaign and ads related data of my adwords account,
as any other adwords user can also sign in and can see data associated with their adwords account ..


please let me know if it is feasible and if it feasible . what step should i follow to make it work like as desired :)

Vishal Vinayak (Adwords API Team)

unread,
Nov 23, 2016, 2:43:36 PM11/23/16
to AdWords API Forum
Hi,

To enable users to see their campaign data using your tool, you would need to follow these steps (assuming you already have a valid developer token):

1) User would need to create OAuth2 credentials using one of the email addresses which is a valid user on the AdWords account that they are trying to target (and not the manager account). 

2) User configures the OAuth2 credentials information (client ID, clientSecret etc.) in your tool.

3) Using the information provided by the user and the developer token (that you already have), you can make a SOAP call to the AdWords API using one of our client libraries or manually using this guide. To fetch the the clientCustomerId (i.e. the 10 digit target AdWords account ID) of the user you can use the CustomerService as explained in one of my previous responses.  

4) Since you have the clientCustomerId of the target AdWords account, you can use something like a CampaignService to fetch campaigns associated with that account.
 
Just to reitreate, AdWords API does not support username/email and password based authentication. Please revert if you have more questions.

Regards,
Vishal, AdWords API Team

Radu Margina

unread,
Dec 1, 2017, 4:17:14 AM12/1/17
to AdWords API Forum
Why user need to create OAuth credentials, user is not IT guy to now how to do this, user wants to login with google and see their AdWords accounts in my app. 
And I already have user accessToken, user already authorized my app to manage his AdWords account, this is not enough to get userCustomerID ?

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Dec 1, 2017, 2:07:57 PM12/1/17
to AdWords API Forum
Hi Radu, 

The OAuth setup is only required to be done once (provided the tokens are valid and credentials don't change). If your application is making calls against user's account, the user will need to authorize the application once which will generate the authorization code during the OAuth setup. You might have used this authorization code to further generate the access token and refresh token. Access tokens are short lived and refresh tokens are long lived (usually years). Your application could save this refresh token and make use of it to make any futhure API calls. 

Once the above setup is done, if you make an API call to CustomerService.getCustomers() without specifying the client customerId in the header, the API will return all the customers directly accessible by the user authenticating the call. 

If you have any additional questions, could you please create a new thread?

Thanks,
Sreelakshmi, AdWords API Team

mavin sheikh

unread,
Aug 1, 2019, 7:42:23 PM8/1/19
to AdWords API and Google Ads API Forum
any solution?



Google Ads API Forum Advisor Prod

unread,
Aug 1, 2019, 10:55:48 PM8/1/19
to adwor...@googlegroups.com
Hi Mavin,

Could you confirm if my understanding is correct that you wish to retrieve the account ID of the Google Ads account currently logged in using the AdWords API or using JavaScript? If yes, then I'm afraid that this is not supported in the AdWords API.

Additionally, JavaScript is currently not included in the AdWords API's supported client libraries.

Thanks and regards,
Peter
Google Ads API Team

ref:_00D1U1174p._5001UEHZnX:ref

Amol Kawale

unread,
Aug 26, 2021, 6:30:56 AM8/26/21
to AdWords API and Google Ads API Forum
Guys am also facing same issue for my system. Customers will do sign at my system to their Google ads account & allow us to access their ads account details like customer ID, campaign, etc... We can get his email, name But I'm not getting anything how to get his 10 digit customer ID using any api in php or JavaScript.

Your help is highly appreciated.

Regards,
Amol

Amol Kawale

unread,
Aug 30, 2021, 7:00:41 AM8/30/21
to AdWords API and Google Ads API Forum
Pls help me guys to find solution...

Google Ads API Forum Advisor

unread,
Aug 30, 2021, 11:19:56 AM8/30/21
to a.ka...@sweply.com, adwor...@googlegroups.com
Hello,

Although there is not a supported Javascript client library at the moment, there is a PHP library. I would recommend looking through the account management guide for more information.

To get the client customer ID, you can query the customer resource.

Regards,
Matt
Google Ads API Team

Google Logo
Matt
Google Ads API Team
 


ref:_00D1U1174p._5001UEHZnX:ref
Reply all
Reply to author
Forward
0 new messages