【发布时间】:2018-11-03 21:01:32
【问题描述】:
我正在关注 Python (2.7) 的 Google Sheets API quickstart tutorial 以完成我正在从事的项目,但我遇到了不知道如何通过的墙。
我非常仔细地按照教程设置了我的 OAuth2 凭据,将文件放在我的 quickstart.py 脚本目录中,并将其重命名为 client_secret.json。
但是,从终端运行脚本会将我带到 错误:403 页面,并显示错误消息 “错误:受限客户端”
执行脚本的最大输出:
nik@debian:~/Documents/Misc/Py$ python quickstart.py
/usr/local/lib/python2.7/dist-packages/oauth2client/_helpers.py:255: UserWarning: Cannot access credentials.json: No such file or directory
warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
Your browser has been opened to visit:
https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fspreadsheets.readonly&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&response_type=code&client_id=(I probably shouldn't give this out)&access_type=offline
If your browser is on a different machine then exit and re-run this
application with the command-line parameter
--noauth_local_webserver
我尝试触摸脚本目录中的 credentials.json 文件,这确实阻止了警告消息的出现,但它仍然没有在凭证文件中填充任何内容。
我的理解是脚本应该为我创建一个凭据文件,考虑到脚本中的范围,并且如果范围发生变化,则需要更新。
到目前为止,这是一个富有成果的项目中缺少的部分,我真的很茫然。我在这里想念什么?
编辑: 评论者指出,OAuth2 对多人来说是损坏的。同时,在整理这些内容的同时,在您的开发者控制台中生成一个 API Key 并使用这段代码来验证您的服务模块
service = build('sheets', 'v4', developerKey=yourAPIKey)
【问题讨论】:
-
请参阅:stackoverflow.com/questions/50507417/… 了解类似问题。它似乎在谷歌方面。
-
还有这个,最先报道的:stackoverflow.com/questions/50501811/…
标签: python python-2.7 google-sheets-api