2

so I was building a project which included me saving some in google drive and this is part of the code I used

gauth = GoogleAuth()
gauth.LoadCredentialsFile("mycreds.txt")
if gauth.credentials is None:
    gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
    gauth.Refresh()
else:
    gauth.Authorize()
gauth.SaveCredentialsFile("mycreds.txt")
drive = GoogleDrive(gauth)

It worked fine for a some days but then I started getting this error

pydrive.auth.RefreshError: Access token refresh failed: invalid_grant: Token has been expired or revoked.

It came from the gauth.Refresh() line so does anyone know why this happened and how to fix it?

vvvvv
  • 25,404
  • 19
  • 49
  • 81
amrha
  • 47
  • 1
  • 9

2 Answers2

6

I ran into a similar problem with pydrive2. The issue is caused by a revokation of your GDrive.

Try to delete the credentials.json in your root directory and authenticate once more.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Paavo Pohndorff
  • 323
  • 1
  • 2
  • 17
  • Thanks, that was the problem I fixed it some time ago but forgot to post the answer here – amrha Sep 28 '20 at 18:57
  • 7
    It keeps happening... Any Idea why my credentials keep being invalid? – Leonardo Rick Mar 18 '21 at 05:05
  • For me didn't work by deleting credentials.json but if I removed mycreds.txt then I was able to relog in to g drive and then worked. Not sure if it will stay working yet. – A Rob4 Feb 09 '23 at 07:32
2

I tried removing settings.yaml and run the code again, it should ask you to "login" to your google account. It worked for me.