Workround: 由于我只需要访问电子表格,我使用gspread代替,oauth2使用它更简单
我尝试使用pydrive(python google drive api)下载文件
我的代码对我有用,我没有改变任何东西,但现在它无法正常工作
我确保将该文件设为公开(即使它是私有的也可以使用)
这是代码的相关部分:
gauth = GoogleAuth()
gauth.GetFlow()
# Try to load saved client credentials
gauth.LoadCredentialsFile("mycreds.txt")
if gauth.credentials is None:
# Authenticate if they're not there
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
# Refresh them if expired
gauth.flow.params.update({'access_type': 'offline'})
gauth.Refresh()
else:
# Initialize the saved creds
gauth.Authorize()
drive = GoogleDrive(gauth)
# Save the current credentials to a file
gauth.SaveCredentialsFile("mycreds.txt")
file1 = drive.CreateFile({'id': '1naQ4crE04nBmsj7yz4GNtmp-PKrCtfTHjl_AfGoTaws'})
file1.GetContentFile('Hello.csv', mimetype='text/csv')
这是我在控制台中遇到的错误:
pydrive.files.ApiRequestError: <HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/1naQ4crE04nBmsj7yz4GNtmp-PKrCtfTHjl_AfGoTaws?alt=json returned "File not found: 1naQ4crE04nBmsj7yz4GNtmp-PKrCtfTHjl_AfGoTaws">
这就是上面的链接显示的内容:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded.
Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued
use requires signup."
}
}
感谢任何帮助,谢谢
答案 0 :(得分:0)
我认为你可以尝试使用凭证文件中的活动访问令牌从邮递员那里点击files.get api。
如果它给出401,则表示您的访问令牌不正确。
如果它给出404,则表示您无权访问该文件或该文件已被删除。