pythonpydrive

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


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?


Solution

  • 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.