像其他人一样,我试图让 Google 刷新令牌工作,以便运行复制和重命名文件的计划任务。
当我第一次在终端中手动进行身份验证时,我的 url 以 &access_type=offline 结尾。但是,当我进入并尝试在 ipython 中手动使用 gauth.Refresh() 时,它会失败并出现与我的凭据文件过期时相同的错误:
pydrive.auth.RefreshError: No refresh_token found.Please set access_type of OAuth to offline.
我如何实际将 access_type 设置为离线?非常感谢任何建议。
我的脚本:
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)
我的 settings.yaml 文件:
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