got access token, didn't get refresh token.

4,090 views
Skip to first unread message

cisc...@gmail.com

unread,
Jul 16, 2015, 8:56:41 AM7/16/15
to adwor...@googlegroups.com
So, I managed to get the SimpleOAuthHandler working, setting up my redirect urls, etc:

    $server = NULL;
    $handler = new SimpleOAuth2Handler($server, $scope);

    $googleOAuthCredentials = new GoogleOAuthCredentials();

    $credentials = array( 'client_id'     => <my client_id>
                                      'client_secret' => <my client secret> ,
                                    );
    $redirectURL = <my redirect url>

    // true means i want an offline token, i.e., give me a refresh token
    $google_url = $handler->GetAuthorizationUrl($credentials, $redirectURL, true);

The generated URL is: 

    https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=<client id>&redirect_uri=<my redirect url>&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords&access_type=offline

Which takes me to the Google login screen. When I select the appropriate account, it comes back to my redirectURL
with a code, which I use to get an access token:

 $token_info = $handler->GetAccessToken($credentials, $code, $redirectURL);

But the token_info I get back doesn't include a refresh token:

Array
(
    [client_id] => <my client_id>
    [client_secret] => <my client secret>
    [access_token] => <my new access token>
    [token_type] => Bearer
    [expires_in] => 3599
    [timestamp] => 1437002357
)

Why wouldn't  access_type=offline cause a refresh token to be returned?

thanks,
Andy

Josh Radcliff (AdWords API Team)

unread,
Jul 16, 2015, 5:49:43 PM7/16/15
to adwor...@googlegroups.com, cisc...@gmail.com
Hi Andy,

Have you requested access for the same user using the same client_id multiple times? I ask because the OAuth guide explains that:

The next time your application requests an authorization code for that user, the user will not be asked to grant consent (assuming they previously granted access, and you are asking for the same scopes). As expected, the response includes an authorization code which may be redeemed. However, unlike the first time an authorization code is exchanged for a given user, a refresh token will not be returned from the authorization code exchange.

Thanks,
Josh, AdWords API Team

cisc...@gmail.com

unread,
Jul 16, 2015, 5:52:41 PM7/16/15
to adwor...@googlegroups.com
Probably, I have had a terrible time beating my way through these examples and sample code. Sounds like
I need to regenerate my client_id again and start over. Joy. I'll try that.

Josh Radcliff (AdWords API Team)

unread,
Jul 16, 2015, 5:56:49 PM7/16/15
to adwor...@googlegroups.com, cisc...@gmail.com
Hi Andy,

Have you tried simply using the GetRefreshToken.php example and its accompanying guide on github? Unless you absolutely need the Web application flow, that example should take care of generating tokens for you.

cisc...@gmail.com

unread,
Jul 16, 2015, 6:02:16 PM7/16/15
to adwor...@googlegroups.com
Ok, thanks Josh, that did it. I pushed forward with running my report, and now I get a "DEVELOPER_TOKEN_NOT_APPROVED" error, so I guess I need to wait for that to happen.



On Thursday, July 16, 2015 at 5:56:41 AM UTC-7, cisc...@gmail.com wrote:

Josh Radcliff (AdWords API Team)

unread,
Jul 16, 2015, 6:15:42 PM7/16/15
to adwor...@googlegroups.com, cisc...@gmail.com
Hi Andy,

Even while your developer token is pending approval, you can use it to issue requests against a test account. Check out our Test Account Guide for more info.

By the way, one of the most common reasons for delays in the token approval process is that people forget to submit the second form that's sent to the developer contact email address. Please make sure you've completed that step.

cisc...@gmail.com

unread,
Jul 16, 2015, 6:25:20 PM7/16/15
to adwor...@googlegroups.com, cisc...@gmail.com
I have not received any emails from the process, so I don't have a second form to fill out. I have checked that email address, and sent tests messages there, but haven't gotten anything from Google on that.  I'll check out the test account 
andy

Josh Radcliff (AdWords API Team)

unread,
Jul 16, 2015, 6:46:03 PM7/16/15
to adwor...@googlegroups.com, cisc...@gmail.com
Hi Andy,

You can use the link I provided in my previous email:

cisc...@gmail.com

unread,
Jul 17, 2015, 2:56:06 PM7/17/15
to adwor...@googlegroups.com, cisc...@gmail.com
Josh - I went through that form already... I assume that I am in the queue and am waiting for a response. Thanks
Reply all
Reply to author
Forward
0 new messages