google-api - 在 Google Calendar API 的上下文中,404 是什么意思?
问题描述
我正在尝试使用Google Calendar APIlist
以编程方式访问我拥有的日历:
r = requests.get(
url="https://www.googleapis.com/calendar/v3/calendars/<the ID of my calendar which looks like mydomain_randomstuff@group.calendar.google.com>/events",
params={
'key': <the key from the API console>,
'singleEvents': True,
'orderBy': 'startTime'
}
此调用失败并显示404
:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
在此 API 的上下文中,该错误实际上意味着什么?
笔记:
- 日历确实存在并且有事件
- API 限制甚至还远未达到
解决方案
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
可以表示两件事之一。您输入的日历 ID 正确,或者您通过身份验证的用户无权访问该日历。确保您使用有权访问该日历的正确用户登录。或者,您可以执行calendar.list,它将返回用户当前有权访问的日历列表。这样您就不必担心可能会错过输入日历 ID。
授权
您使用events.list的方法需要授权(用户许可)才能访问他们的日历。可以在文档页面中看到
您需要使用 Oauth2 和上述范围之一来验证您的用户。然后,您将拥有一个可用于访问此日历的访问令牌。
apikey
API 密钥用于访问公共数据。除非您的日历设置为公开,否则您将无法使用它来查看活动。另请记住,api 密钥无权更新公共日历,您仍需要通过身份验证才能对其进行更改。
服务帐号
如果这是服务器到服务器应用程序,您应该使用服务帐户而不是 API 密钥。您需要做的就是将服务帐户添加为谷歌日历上的用户,就像您添加任何其他用户一样。然后它将可以访问您的日历。
推荐阅读
- c++ - libpqxx:如何确定一个连接是否需要密码
- python - 如何使用条件向量化 for 循环而不是遍历 Pandas DataFrame
- c++ - C++ 与 C 中的 static_assert 用法
- django - 使用 VueJS 前端项目部署 DRF API
- django - Django 在另一个选项卡上打开用户输入的 url 链接
- postgresql - GIN 索引没有被自动清空
- visual-studio - Visual Studio 控制台应用程序 - 程序终止时自动关闭控制台窗口
- python - 如何在 matplotlib 中扩展线性回归图
- git - 继续删除最新的历史提交 git
- quartz.net - Quartz.NET 调度程序在运行几次后停止