Reputation: 47
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?
Upvotes: 2
Views: 5011
Reputation: 1200
Let remove content of mycreds.txt first.
Then you have to create a settings.yaml file and set get_refresh_token
is True
This is the setting file that I am using, hope it help
client_config_backend: 'settings'
client_config:
client_id: "<copy client_id from client_secrets.json here>"
client_secret: "<copy client_secret from client_secrets.json here>"
get_refresh_token: True
save_credentials: True
save_credentials_backend: 'file'
save_credentials_file: 'mycreds.txt'
oauth_scope:
- "https://www.googleapis.com/auth/drive"
Upvotes: 1
Reputation: 21
I tried removing settings.yaml
and run the code again, it should ask you to "login" to your google account. It worked for me.
Upvotes: 2
Reputation: 333
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.
Upvotes: 7