Like others, I'm trying to get the Google Update token to work in order to run scheduled tasks that copy and rename files.
When I first manually authenticate inside the terminal, my url ends with & access_type = offline. However, when I log in and try to use gauth.Refresh () manually in ipython, it fails with the same error as when my credentials file expired:
pydrive.auth.RefreshError: No refresh_token found.Please set access_type of OAuth to offline.
How can I set access_type offline? Any suggestions are welcome.
I was here , here and here to fix this problem.
My script:
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LoadCredentialsFile("GoogleDriveCredentials.txt")
if gauth.credentials is None:
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
print "Google Drive Token Expired, Refreshing"
gauth.Refresh()
else:
gauth.Authorize()
gauth.SaveCredentialsFile("GoogleDriveCredentials.txt")
drive = GoogleDrive(gauth)
My settings.yaml file:
client_config_backend: settings
client_config:
client_id:
client_secret:
save_credentials: True
save_credentials_backend: file
save_credentials_file: credentials.json
get_refresh_token: True
oauth_scope:
- https://www.googleapis.com/auth/drive