oauth - PyDrive guath.Refresh() and Refresh Token Issues -


like others, i'm trying google refresh token work in order run scheduled tasks copy , rename files.

when first manually authenticate within terminal, url ends in &access_type=offline. however, when go in , try manually use gauth.refresh() in ipython, fails same error when credentials file expires:

pydrive.auth.refresherror: no refresh_token found.please set access_type of oauth offline. 

how set access_type offline? suggestions appreciated.

i have been here, here, , here trying troubleshoot this.

my script:

from pydrive.auth import googleauth pydrive.drive import googledrive  gauth = googleauth()  # try load saved client credentials gauth.loadcredentialsfile("googledrivecredentials.txt") if gauth.credentials none:     # authenticate if they're not there     gauth.localwebserverauth() elif gauth.access_token_expired:     # refresh them if expired     print "google drive token expired, refreshing"     gauth.refresh() else:     # initialize saved creds     gauth.authorize() # save current credentials file gauth.savecredentialsfile("googledrivecredentials.txt") drive = googledrive(gauth) 

my settings.yaml file:

client_config_backend: settings client_config:   client_id: ###actual client_id###   client_secret: ###actual 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 

i have been there , below works me.

from pydrive.auth import googleauth pydrive.drive import googledrive    gauth = googleauth() gauth.localwebserverauth() gauth.loadcredentialsfile(gauth) 

create new folder above code quickstart.py in root dir.
download client_sercrets.json google drive api credentials , put in root
put settings.yaml file in root folder
run quickstart.py console , open browser ask authorise app.
once process completed, create credentials.json file in root directory.
access token should able refresh now.

few things note drive api settings, should web application type, in authorize javascript "http://localhost:8080" , in authorized redirect uris "http://localhost:8080/"

if successful, carry on "credentials.json", "client_secrets.json", "settings.yaml" files production root dir , should work.

hope helps!


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -