can we use access token from adwords api to google_client?

421 views
Skip to first unread message

Joven Albarida

unread,
Jul 1, 2016, 3:37:09 PM7/1/16
to AdWords API Forum
Hi Adwords Team,

I'm trying to get the Email address using Google_Client Library on PHP

But the access token was created from AdWords API? Is this kind of possible?

If Yes, may I request if you can direct me to the references.  If No, is there another way to do this by getting the Email address?

Thank you.,

Anthony Madrigal

unread,
Jul 1, 2016, 4:34:20 PM7/1/16
to AdWords API Forum
Hi,

There is currently no way to get the email address using AdWords API. Access tokens are generated through the API. Here is a guide on how that is done.

Regards,
Anthony
AdWords API Team

Joven Albarida

unread,
Jul 12, 2016, 8:24:54 AM7/12/16
to AdWords API Forum
What I mean is I already got the Access Token from AdWords API, I just wondering if I can use that Access Token to Google_Client, because as I understand on Google OAuth2 documentation, the OAuth are only done once so it only provide One access token

I know that AdWord API dont response Email address user choose to use.  But its possible to get the Email Address on Google_Client, the only confusing part to me is that the OAuth is only done once and this two APIs a seperate login


To explain the application I'm doing, it is a similar feature on Swydo when connecting multiple account


Thanks,

Anthony Madrigal

unread,
Jul 12, 2016, 5:22:07 PM7/12/16
to AdWords API Forum
Hi Joven,

Thanks for the details. However, I am still unclear what you mean by Google_Client. Do you mean the Google APIs Client Library for PHP

Thanks again,
Anthony
AdWords API Team

Zweitze

unread,
Jul 13, 2016, 8:18:28 AM7/13/16
to AdWords API Forum
This is certainly possible but I don't have an exact answer.
When you request access from the user, you supply which API you want access to - AdWords API in this case. After a user logs in, he sees a page asking to give access to his AdWords information.
Actually you can ask for access to multiple APIs at the same time. Say you want access to AdWords and Analytics, the user logs in and then see a page asking for permission to access both AdWords and Analytics. When the user grants this access, you can use the same access token for both AdWords and Analytics.

Well: Another API has minimal email access, if you include that, you can use that API (and the returned access token) to ask for the email address. Unfortunately I don't have the name of the grant at hand. But I also don't program PHP so I can't help you any further.

Still, this is the direction to go. I hope it makes sense.

Chirag

unread,
Jul 14, 2016, 1:19:04 AM7/14/16
to AdWords API Forum
Hello Joven,

Yes, Zweitze is right.

When you get refresh token to get access of Adwords API, you also need to include scope to get User Email along with Adwords API scope.
To get user email you can use Google OAuth2 API v2 scope.

Scope to be used to get User email : https://www.googleapis.com/auth/userinfo.email


Thanks,

Joven Albarida

unread,
Jul 14, 2016, 10:12:31 AM7/14/16
to AdWords API Forum
Sorry I forgot to attached the link

Yes Anthony, I'm referring to the Google APIs Client Library for PHP?

Thanks,

Joven Albarida

unread,
Jul 14, 2016, 10:26:53 AM7/14/16
to AdWords API Forum
Thanks Chirag, will study what you mean on this... I only tried to set this scope under AdWords API but doesn't return the Email 

This my following steps in-case there something wrong on what im doing :)

+ On background I set all required credential to Access AdWords API, then I also set the "scopes"
+ After all that I redirect the user to Auth URL for the application get the access token, refresh token etc.
Format of the request:
https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords&response_type=code&redirect_uri=http%3A%2F%2Fdev.xxxxxxxxxxx.com%2Faccount%2Fmyapi&client_id=254682842771-e0pgjq248s5doj059e3qo87a91l4m4gc.apps.googleusercontent.com&from_login=1&as=2ff3f2831fd61830&authuser=0

+ After user select his account, it will redirected to the set redirection URL together with "code" parameter  <-- (So here I'm expecting to receive the email address too? Is that correct)

+ After the application received the code, I will use that to get the "Access token, Refresh token" which is working fine. Then I will saved this token to my storage for later use

+ On my application I also need to save the choosed Email (So this is my main problem im stuck with, so that I post my question on this forum :)


Again appriciate your help in advance, thanks guys 

Chirag

unread,
Jul 15, 2016, 2:40:17 AM7/15/16
to AdWords API Forum
Hello Joven,

From your request I am seeing that you have not included the scope to get email.

https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords&response_type=code&redirect_uri=http%3A%2F%2Fdev.xxxxxxxxxxx.com%2Faccount%2Fmyapi&client_id=254682842771-e0pgjq248s5doj059e3qo87a91l4m4gc.apps.googleusercontent.com&from_login=1&as=2ff3f2831fd61830&authuser=0

So Your request should be like this

https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords%2Bhttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&response_type=code&redirect_uri=http%3A%2F%2Fdev.xxxxxxxxxxx.com%2Faccount%2Fmyapi&client_id=254682842771-e0pgjq248s5doj059e3qo87a91l4m4gc.apps.googleusercontent.com&from_login=1&as=2ff3f2831fd61830&authuser=0

After user select his account, it will redirected to the set redirection URL together with "code" parameter  <-- (So here I'm expecting to receive the email address too? Is that correct)
--> No, You cannot get email address directly. You need to make curl request to get email address.

You need to call curl request after getting Refresh Token / Access Token.
Curl Url should be like this

Under the curl response you can get email for authorize user.

Hope this helps.

Joven Albarida

unread,
Jul 16, 2016, 5:30:27 AM7/16/16
to AdWords API Forum
Many thanks Chirag, for this help. I will try the on you posted here to confirm :)

Burak Karakan

unread,
Aug 29, 2016, 11:46:26 AM8/29/16
to AdWords API Forum
Hello Chirag.

I have been trying to get the user email as well, and with the url you provided, I am now able to get user name, profile picture, user id, gender etc. but there is no email address under the response, what should be the way to go now to get the email address?

Thanks.

15 Temmuz 2016 Cuma 09:40:17 UTC+3 tarihinde Chirag yazdı:

Chirag

unread,
Aug 30, 2016, 2:16:19 AM8/30/16
to AdWords API Forum
Hello Burak,

You must be missing to pass extra scope https://www.googleapis.com/auth/userinfo.email along with Adwords API scope.

If you have passed this scope while getting access token, you can do curl request ("https://www.googleapis.com/oauth2/v2/userinfo?access_token="YOUR_ACCESS_TOKEN";) to get user email.

Thanks


Thanks,
Reply all
Reply to author
Forward
0 new messages