PHP API v201609 - How to refresh token?

225 views
Skip to first unread message

Adam Haining

unread,
Feb 9, 2017, 8:24:05 PM2/9/17
to AdWords API Forum
I'm using the PHP API v201609.  It is working great, except that the documentation states it will refresh the token for you automatically.  There are no code examples for how to implement this.  I've tried everything under the sun with no luck.  Can someone give me some tips and pointers for getting this to work?

Peter Oliquino

unread,
Feb 9, 2017, 10:58:39 PM2/9/17
to AdWords API Forum
Hi Adam,

Refreshing of expired access tokens happens when the Credential object is instantiated in the client libraries. To better give you an idea of the process, first you will need to have a refresh token that is generated manually. Please note that due to a number of reasons, the refresh token may also expire or become invalid and you'll need to reauthorize the application and generate a new refresh token as stated here.

Once your refresh token details have been provided in your configuration file, the client library will then automatically refresh any expired access tokens when Credential object is created. I hope this has been helpful.

Thanks and regards,
Peter
AdWords API Team

Adam Haining

unread,
Feb 10, 2017, 12:42:09 AM2/10/17
to AdWords API Forum
Thanks.  I'm able to manually get a new token without any problems.  I haven't been able to get it to refresh or see where it gives me a new token.  I have a few questions:
  1. Can I refresh the token after it expires?  I've tried everything I can think of, including using the OAuth2TokenRefresher class to try and get a new token both before and after the token expires.
  2. If I cannot, how close to expiration does the token have to be to expiration to receive a new token?  Can I force it at any time?  Do I essentially need to have a cron job that checks any current tokens?
Do you have any specific code examples?  This is the one thing I feel is lacking greatly in the documentation and the one thing I need to migrate our codebase to production.  Thanks!

Josh Radcliff (AdWords API Team)

unread,
Feb 10, 2017, 8:52:22 AM2/10/17
to AdWords API Forum
Hi Adam,

Could you file an issue for this problem on the PHP library issues page? The engineers working on the library are actively monitoring that page and should be able to answer your questions.

Thanks,
Josh, AdWords API Team

Adam Haining

unread,
Feb 10, 2017, 1:46:30 PM2/10/17
to AdWords API Forum

Thanet Knack Praneenararat (AdWords API Team)

unread,
Feb 12, 2017, 11:33:54 PM2/12/17
to AdWords API Forum
Hello Adam,

Vincent will answer your questions in the issue soon.
Sorry if it takes a bit too long. :)

Cheers,
Thanet, AdWords API Team
Reply all
Reply to author
Forward
0 new messages