Refresh token not being returned in oauth2info

268 views
Skip to first unread message

Mike Swan

unread,
Jun 5, 2014, 4:53:13 PM6/5/14
to adwor...@googlegroups.com
Hi All,

I have scoured the group and the Internet (SO, etc.) and I can't find any direction.  For some reason a refresh token is not being returned through the API along with the access token.  

My auth URL looks like this:


It returns this:


Which gets put through this script:

 
// Create a new user and set the oAuth settings
$user = new AdWordsUser();
$user->SetOAuth2Info(array(
    "client_id" => 'xxx.apps.googleusercontent.com',
    "client_secret" => "xxx"
));

$authCode = $_REQUEST['code'];

$OAuth2Handler = $user->GetOAuth2Handler();
$user->SetOAuth2Info($OAuth2Handler->GetAccessToken($user->GetOAuth2Info(), $authCode, $callbackUrl));

Everything works fine, but this is all I am getting back:

[oauth2Info:AdsUser:private] => Array

        (

            [client_id] => xxxx.apps.googleusercontent.com

            [client_secret] => xxxxxxx

            [access_token] => ya29.xxxxxxxxxxxxx

            [token_type] => Bearer

            [expires_in] => 3599

            [timestamp] => 1401998014

        )

So I can pull the data I need, but I have to reauthorize every time.  This is using an MCC.  Is there something I am missing?  

Thanks for your help.

Mike


Josh Radcliff (AdWords API Team)

unread,
Jun 6, 2014, 6:23:59 PM6/6/14
to adwor...@googlegroups.com
Hi Mike,

This is, admittedly, a bit of a wild guess, but I noticed that when I went through the refresh token example my auth URL did not include a state parameter. Maybe give it a shot with that parameter removed?

Cheers,
Josh, AdWords API Team

Mike Swan

unread,
Jun 6, 2014, 9:09:21 PM6/6/14
to adwor...@googlegroups.com
Hi Josh,

I removed the state parameter and same result: new auth creds, able to pull data, but no refresh token included.  Anything other ideas?   I noticed my CC in my billing preferences expired, does this have anything to do with it?  Like I said, I can pull data, just have to re-authenticate each time.  Thanks for your attention.

Mike 

Rob

unread,
Jun 9, 2014, 4:05:40 AM6/9/14
to adwor...@googlegroups.com
Hi Mike,

Have you tried adding the prompt=consent flag to your request? If you've already authorized the app once before, then this flag seems to be required in order to get a refresh token on subsequent requests.

jody stein

unread,
Mar 16, 2015, 10:38:07 PM3/16/15
to adwor...@googlegroups.com
I am running into the same problem. I have not made any changes however I am not able to add new users. The refresh token is no longer being returned. 

Here is the request URL I am using. 


I receive the response with no error. However the refresh_token is no longer being sent. 

Am I doing something wrong here? or did something change recently?

Any help would be greatly appreciated!

Josh Radcliff (AdWords API Team)

unread,
Mar 17, 2015, 2:02:04 PM3/17/15
to adwor...@googlegroups.com
Hi,

I may be misunderstanding your question, but I think you're missing a step. After the user accepts the OAuth prompt, your redirect endpoint will receive an authorization code (the https://domain.com/pro/login/googleredirect.php?code=4/xxx request below), which it then must submit in order to get the refresh token, as illustrated in the OAuth guide.

Thanks,
Josh, AdWords API Team

jody stein

unread,
Mar 17, 2015, 2:45:41 PM3/17/15
to adwor...@googlegroups.com
Yes here is the PHP to process the code returned which used to return refresh_token an now returns just the client_id and client_secret. I am using the right paramenters, access_type=offline and tried adding prompt=consent. 

$user = new AdWordsUser();
$user->LogAll();
$handler = $user->GetOAuth2Handler();
$oauth2Info = $handler->GetorRefreshAccessToken($user->GetOAuth2Info(), $code, $redirectUri);
// I also tried this version just in case which returns the same thing
//$oauth2Info = $handler->GetAccessToken($user->GetOAuth2Info(), $code, $redirectUri);
$user->SetOAuth2Info($oauth2Info);

if(isset($oauth2Info['refresh_token'])){
$refreshtoken=$oauth2Info['refresh_token'];
$accesstoken=$oauth2Info['access_token'];
$timestamp = isset($oauth2Info["timestamp"]) ? $oauth2Info["timestamp"] : 0;
$expiresIn = isset($oauth2Info["expires_in"]) ? $oauth2Info["expires_in"] : 0;
//do the rest of the processing to save token
}

Does that make more sense?

Josh Radcliff (AdWords API Team)

unread,
Mar 17, 2015, 5:28:41 PM3/17/15
to adwor...@googlegroups.com
Hi,

Thanks, that clears things up a bit.

I just tried running the GetRefreshToken.php example using my account and I was able to obtain a refresh token without issues. Could you modify your code so that you log the contents of $oauth2Info? I'd be curious to see what (if anything) is set on that object.

If you post the contents here, please make sure you remove any sensitive information first.

Thanks,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages