Google 日历 API 密钥不允许通过简单的 GET 请求访问公共日历

Google Calendar API key doesn't allow access to public calendar via simple GET request

本文关键字:日历 请求 GET 访问 密钥 API 不允许 Google 简单      更新时间:2023-09-26

通过Google API浏览器,我可以使用日历ID访问我的公共日历事件列表。所以我知道很多事情都是对的

https://developers.google.com/google-apps/calendar/v3/reference/events/list

他们使用的GET示例如下所示:

GET
https://www.googleapis.com/calendar/v3/calendars/iu8chrc23t5nuejb3q28lt970o%40group.calendar.google.com/events?key={YOUR_API_KEY}
X-JavaScript-User-Agent:  Google APIs Explorer
我的

理解是,我需要做的就是将我的 API 密钥粘贴到表示 YOUR_API_KEY 的部分,我应该能够通过简单地将该 url 放入我的浏览器来检索正确的响应。

假设我的 API 密钥ABCDEF1234

然后我将其粘贴到浏览器中并按 go:

https://www.googleapis.com/calendar/v3/calendars/iu8chrc23t5nuejb3q28lt970o%40group.calendar.google.com/events?key={ABCDEF1234}

不幸的是,我得到的回复告诉我出了点问题

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "keyInvalid",
    "message": "Bad Request"
   }
  ],
  "code": 400,
  "message": "Bad Request"
 }
}

起初我以为我没有等待足够长的时间才能激活密钥,但现在已经超过 24 小时了,所以我不确定为什么密钥会无效。

为了回答这个问题的答案,我确定我使用的是公钥。

我对此的唯一线索是 API 密钥与谷歌"项目"相关联,但我的简单 GET 请求不是。我的最后一个应用程序是一个简单的静态网页,里面有一个小脚本来显示即将到来的日历事件,所以给出的Java,PHP,Ruby,Python等示例不适用。

摘要:公共日历,在 API v3 中轻松访问即将发生的事件(我之前在 v2 中这样做过(。

我知道

这个问题已经很老了,但也许它可以帮助其他偶然发现同样事情的人(比如我(。

解决方案:还必须更换花括号。因此,您的请求尤其应如下所示:https://www.googleapis.com/calendar/v3/calendars/iu8chrc23t5nuejb3q28lt970o%40group.calendar.google.com/events?key=ABCDEF1234

否则,您将收到显示的错误消息。此外,请确保使用的日历是公开的。如果不是,您将收到以下错误消息:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}