I am using the Google PHP SDK to connect to Google My Business and get an access token.
After connection with Google (Client), everything works, but when around 1-2 days pass, I start to get "Bad Request" and error code "invalid_grant" from
here.
Meaning that the refresh token is not valid anymore. Then I have to disconnect the google connection and re-connect to make it work for 1-2 days.
I am also setting the refresh token for offline use. Any ideas what is wrong?
My Answer:
There could be a few reasons why your refresh token is becoming invalid after 1-2 days. Here are some things to check and consider:
1. Make sure you are storing the refresh token securely and not accidentally overwriting it with a new refresh token each time you connect to Google. If you are getting a new refresh token each time, it will invalidate the previous one.
2. Check if the user has revoked access to your application in their Google account settings. If they revoke access, the refresh token will become invalid.
3. Make sure you are requesting the "offline" access type when exchanging the authorization code for the refresh token. This will ensure that you receive a refresh token that can be used indefinitely.
4. Check if there are any restrictions or limitations on the Google API usage that could be causing the refresh token to become invalid.
5. Consider implementing a mechanism to automatically refresh the access token using the refresh token before it expires, rather than waiting for it to become invalid.
By checking these points and making sure your implementation is correct, you should be able to maintain a valid refresh token for continuous access to Google My Business.
Rate this post
5 of 5 based on 5210 votesComments