Unable to get OAuth 2.0 refresh_token with GetRefreshToken.php

1,092 views
Skip to first unread message

Mark

unread,
Aug 22, 2013, 4:07:54 AM8/22/13
to adwor...@googlegroups.com

Having used the adwords API for some years and upgraded various versions of the PHP client library including the apility days, we are having major problems with a migration from v201209 to v201306

Our use is solely to run our own adwords account by automatically changing adverts prices,  adding new adgroups and keyword for new products.

Currently we maintain some 13K + adgroups.

We use the PHP client library as the base of our development for authentication, updating and communication included from within our own scripts which communicate directly with our database servers.

As you can imagine as we have been offline since the sunset of v201209 this is now critical.


Currently,  we have downloaded the v201306 php client library and uploaded it to a test area on our server.

We have followed the instructions about getting an OAuth 2.0 refresh_token and that is where we have hit a brick wall.

We have the client_id, client_secret both of which have been placed into the src/Google/Api/Ads/Adword/auth.ini file.

The next step was to run GetRefreshToken.php

We have ran this from  [url]/examples/AdWords/Auth/GetRefreshToken.php and initially ended up with a blank page.

Some debug later and we found that the command:

if (__FILE__ != realpath($_SERVER['PHP_SELF'])) {
 
  return;
}


the realpath command is returning false and therefore the two values did not match and consequently the script was just stopping without any message hence the white screen.

So we commented out these commands and tried again.   This time we got a little further but still received an error.

Log in to your AdWords account and open the following URL:
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=[REMOVED].apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fadwords.google.com%2Fapi%2Fadwords%2F&access_type=offline

After approving the token enter the authorization code here:
Your OAuth2 Credentials are incorrect.
Please see the GetRefreshToken.php example.
{
  "error" : "invalid_request"
}


Even with the error, we tried to use the url by manually posting it in a browser but that give us an error that the url was incorrect.

Having trolled through many forum and web posts we are still no further forward as to what could be the problem.


Any assistance to just get past this first step of getting a refresh_token would be appreciated

Alan Coleman

unread,
Aug 29, 2013, 7:00:30 AM8/29/13
to adwor...@googlegroups.com
Hi Mark,

I'm currently working through the same situation myself. Frustrating isn't the word!

Are your client_id and client_secret pair from your MCC Account? I think this is important, although it's hidden away in the documentation.

I'd be interested to know how you get on with this, I'll keep you posted with my developments.

Thanks 

Ewan Heming

unread,
Aug 29, 2013, 7:20:49 AM8/29/13
to adwor...@googlegroups.com
Hi Alan,

You shouldn't need a new developer token as you can use any token with any authorized AdWords account. You can also use any client_id and client_secret to generate the OAuth tokens. 

Quite a few of the people I've worked with have had problems generating tokens when they just want to authorize a single account. I've found that using Google's OAuth playground was the simplest way to grab some tokens. I've already put together some instructions, so I'll publish them and post the link here.

Regards,

Ewan

Alan Coleman

unread,
Aug 29, 2013, 7:27:12 AM8/29/13
to adwor...@googlegroups.com
Thanks Ewan! Look at me, giving out bad advice on the forum!

yuhao feng

unread,
Aug 29, 2013, 6:45:07 PM8/29/13
to adwor...@googlegroups.com
Hi Ewan,

I did try using OAuth playground to generate token, however it didn't work so well. I use the token I got from the Playground in my java code, it didn't response.

My situation is very strange, I'm using Eclipse+Maven to code for adwords API, but until now i couldn't get a OAuth token from the example (adwords-axis-examples) code-GetRefreshToken. I got bugs in the editor, like "Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target" 

I just want to using google adwords API to replace the adwords user-interface one! Is it this hard??

Thanks!

Ewan Heming

unread,
Aug 30, 2013, 7:06:50 AM8/30/13
to adwor...@googlegroups.com
Hi Yuhao,

I think that your problem might be to do with your JDK setup, not the API, and this thread should solve your problem. I'll post the OAuth playground example later today.

Regards,

Ewan

Ewan Heming

unread,
Aug 31, 2013, 2:32:32 PM8/31/13
to adwor...@googlegroups.com
Hi Alan,

If you haven't already worked it out, I put some instructions together for using the OAuth Playground with the AdWords API.

Regards,

Ewan
Reply all
Reply to author
Forward
0 new messages