Reputation: 393
I am using Google Analytics API to fetch analytics data. I tried to authenticate it using following steps:
But after a few days, the refresh token expires although it is mentioned that the refresh token's validity is life long.
Upvotes: 39
Views: 55804
Reputation: 1053
Had this issue with Woocommerce Bookings Calendar Sync app. Kept getting disconnected and there was nothing in the documentation. Reached out to their support who told me to go to the OAuth consent screen and change Publishing status from "Testing" to "In production"
This is the error I noticed:
ERROR Unable to fetch access token with refresh token. Google sync disabled until re-authenticated. Error: "invalid_grant", "Token has been expired or revoked." NOTICE Invalid access token. Reconnect with Google necessary. Code 0. Message: Invalid token format.
Upvotes: 0
Reputation: 39
What I did:
Upvotes: 3
Reputation: 341
I needed to send mails from a gmail account that I have access to, using nodemailer. It works for a couple of days before my refresh token is mysteriously revoked, even though the account belongs to me. A google search brought me here and I had been watching for a while hoping someone would help with a solution.
As you mentioned, this seems to happen with only test/unverified apps and I'm guessing google revokes tokens for such applications in your account after a few days. After much trials and errors, here is what I did.
NOTE: This is solution is only applicable to accounts you own, otherwise you must verify your app to access other people's accounts
I could not find anything related anywhere else.
Upvotes: 22
Reputation: 936
If your app is in testing mode then user tokens will expire in 7 days. Please find this explanations here: https://support.google.com/cloud/answer/10311615#zippy=%2Ctesting
Upvotes: 78
Reputation: 1837
My problem was when I've added access_token
instead of refresh_token
.
Upvotes: 0
Reputation: 73
The solution is to delete your token.json
file to force Google to find a new token.
I was able to get it to work WITHOUT a verified app. Perhaps the refresh()
method will work once my app is verified. Not sure on that one.
Upvotes: 2
Reputation: 516
This issue seems to be for unverified apps, Simply delete the token file from your project and rerun the project, it will create a new token.
Upvotes: 0
Reputation: 87
The other answer pointed me in the right direction but for me the option was located somewhere else: security > security checkup/security issues found > context menu next to your app > dismiss
Upvotes: 7