0

I want to fetch Google reviews using the Google business API on my WordPress Website. As we know that an access_token is required, but it always expires after 1 hour. Does anyone know how we can fetch the new access_token using refresh token?

For example, we have access_token and refresh_token, can we generate the new token using those credentials?

Thank you

theduck
  • 2,589
  • 13
  • 17
  • 23
mgo
  • 1

1 Answers1

0

Normally, if you have saved the first access token you recieved, it should contain a refresh token. If you use setAccessToken() to tell your client about that access token, the PHP client will auto-refresh the access token if it has expired.

You can use the setTokenCallback() method to grab and permanently save that new access token so it can be reused. Doco for setTokenCallback() is here: https://github.com/googleapis/google-api-php-client#updating-tokens

You could alternatively do a manual token refresh with the fetchAccessTokenWithRefreshToken() method - a great, easy to follow, example is in the quickstart here (for Calendar API, but principles are the same): https://developers.google.com/calendar/quickstart/php

Reading the quickstart should be a huge help to you in making sense of all if this!

Brian C
  • 837
  • 1
  • 10
  • 20