PyDrive guath.Refresh () and Update Tokens

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()

# Try to load saved client credentials
gauth.LoadCredentialsFile("GoogleDriveCredentials.txt")
if gauth.credentials is 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 the saved creds
    gauth.Authorize()
# Save the current credentials to a 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
+4
1

, .

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive   
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
gauth.LoadCredentialsFile(gauth)

quickstart.py .
client_sercrets.json api Google Drive
settings.yaml
quickstart.py , , .
, credentials.json .
.

, API- , - Authorize Javascript " http://localhost:8080" URI " http://localhost:8080/"

, "credentials.json", "client_secrets.json", "settings.yaml" .

, !

0

Source: https://habr.com/ru/post/1609604/


All Articles