I can't obtain a refresh_token from AdWords API despite I set access_type to "offline"

260 views
Skip to first unread message

Sebastian Piskorski

unread,
Dec 7, 2016, 9:44:11 AM12/7/16
to AdWords API Forum

User selects his account and authenticate my application to use his AdWords data. In response I get code https://mysite.tld/integrate/adwords?state=xxx-xxx-xxxx&code=4/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx#

And my service process this code passing it to Google SDK. Using `SimpleOAuth2Handler` method `GetAuthorizationUrl` is called. Goolge SDK then tries to obtain token sending following request, but response have no refresh_token.

Example response body:
{
 
"access_token": "ya29.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
 
"token_type": "Bearer",
 
"expires_in": 3341
}


I use google-php-lib v201605.

How to obtain refresh_token. What do I miss?

Sebastian Piskorski

unread,
Dec 7, 2016, 10:55:50 AM12/7/16
to AdWords API Forum
I have even used example from library: GetRefreshToken.php

This is the output:

/usr/local/bin/php /path/to/app/vendor/googleads/googleads-php-lib/examples/AdWords/Auth/GetRefreshToken.php
Log in to your AdWords account and open the following URL:
https
://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=xxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fmysite.tld%2Fintegrate%2Fadwords&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords&access_type=offline


After approving the token enter the authorization code here: 4/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


PHP
Notice:  Undefined index: refresh_token in /path/to/app/vendor/googleads/googleads-php-lib/examples/AdWords/Auth/GetRefreshToken.php on line 90
Notice: Undefined index: refresh_token in /path/to/app/vendor/googleads/googleads-php-lib/examples/AdWords/Auth/GetRefreshToken.php on line 90
PHP
Stack trace:


PHP  
1. {main}() /path/to/app/vendor/googleads/googleads-php-lib/examples/AdWords/Auth/GetRefreshToken.php:0
Call Stack:
PHP
Notice:  Undefined index: refresh_token in /path/to/app/vendor/googleads/googleads-php-lib/examples/AdWords/Auth/GetRefreshToken.php on line 92
   
0.0008     241592   1. {main}() /path/to/app/vendor/googleads/googleads-php-lib/examples/AdWords/Auth/GetRefreshToken.php:0


Your refresh token is:


Notice: Undefined index: refresh_token in /path/to/app/vendor/googleads/googleads-php-lib/examples/AdWords/Auth/GetRefreshToken.php on line 92


Call Stack:
   
0.0008     241592   1. {main}() /path/to/app/vendor/googleads/googleads-php-lib/examples/AdWords/Auth/GetRefreshToken.php:0


In your auth.ini file, edit the refresh_token line to be:
refresh_token
= ""
PHP
Stack trace:
PHP  
1. {main}() /path/to/app/vendor/googleads/googleads-php-lib/examples/AdWords/Auth/GetRefreshToken.php:0


Process finished with exit code 0

Shwetha Vastrad (AdWords API Team)

unread,
Dec 7, 2016, 2:45:52 PM12/7/16
to AdWords API Forum
Hi Sebastian,

Can you confirm that you followed the steps provided here to retrieve your refresh token? The reason GetRefreshToken.php didn't work either is because the response didn't contain a refresh token. Could you try getting the refresh token using this command? 

curl \
     -d code=your-authorization-code \
     -d client_id=your-client-id \
     -d client_secret=your-client-secret \
     -d redirect_uri=your-redirect-uri \
     -d grant_type=authorization_code https://accounts.google.com/o/oauth2/token

This will help me determine if the credentials have been setup correctly. Please use Reply privately to author if you're sending private information.

Regards,
Shwetha, AdWords API Team.

Sebastian Piskorski

unread,
Dec 23, 2016, 8:59:24 AM12/23/16
to AdWords API Forum
Solution was to use:

prompt=consent

istead of:

approval_prompt=force

because API have changed.

This can be marked as solved.
Reply all
Reply to author
Forward
0 new messages