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