Google API refresh token has been expired or revoked [duplicate]
Asked Answered
C

1

7

I am using a Google Ads php library (https://github.com/googleads/googleads-php-lib) to manage my own google ads account, following Google's instructions here (https://developers.google.com/adwords/api/docs/guides/first-api-call)

(I've actually been doing this for many years without a problem, but I recently switched over to using a different project in the Google Cloud Platform, so I had to update my credentials and get a new refresh token)

To get a new refresh token, I ran the php script called GetRefreshTokenWithoutIniFile.php (which allows me to grant offline access and retrieve a new refresh token, which I store in a file auth.ini for future use).

The refresh token last for a few days, before I see this error:

{
    "error" : "invalid_grant",
    "error_description" : "Token has been expired or revoked."
}

I have been using the above method for years and the refresh token has never expired. However, it now seems to expire every couple of days. I am certainly not 'running out' of refresh tokens (I only request one), and the user is not revoking access (the user is me). For that reason, these similar answers don't help me:

Any more ideas?

Chandrachandragupta answered 22/4, 2021 at 15:54 Comment(4)
@daimto Please vote to reopen, as there is currently no known solution to this problem!Chandrachandragupta
invalid_grant means that the refresh token you have has expired. There are a number of causes for that you have only named one. Why not read How to Ask open a new question show minimal reproducible example and show the error message.Lapstrake
Hi @DaImTo, I believe I have quite clearly listed 4 causes (not 1). I explain in my post above that (1) my token has not been revoked by me, (2) no security issues, (3) not requested too many refresh tokens, and (4) I am in production mode. If you know of any others, please do share! You will also see that I have included the error message in my post above, and I have also included the link to the documentation from which my code was created. Anyway, as I state above, the issue is not the code since it was working fine before this. I would appreciate more specific advice!Chandrachandragupta
This is not a duplicate question and has no answerJonejonell
C
4

UPDATE: This did not solve the problem

According to Token has expired or revoked - Google Ads, a refresh token won't persist unless the app is in 'production' mode.

The recommended solution is to select "Publish App" from the Google API console. I tried this out, but unfortunately, after a few days of using the refresh token successfully, the refresh token has expired again.

Chandrachandragupta answered 22/4, 2021 at 15:54 Comment(1)
Perhaps the token expired because it was issued when your app was in development mode. Once you published the app, try deleting your saved OAuth response and recreating it (authorize the app again). The refresh token in this response should not be expiring as long as you keep using it.Phillada

© 2022 - 2024 — McMap. All rights reserved.