Google 日历 API 批量插入已停止

Google Calendar API batch inserting has stopped working

我有一个应用程序已成功使用 HTTP 批处理请求通过 Google 日历 API 插入、编辑和删除事件。在过去的几天里,批次中的单个请求开始返回 404 错误(尽管批次本身获得了 200 成功响应)。使用相同的授权发出与单独请求相同的请求 header 仍然有效。

我很确定这与作为我们的端点的 forthcoming shutdown of Google's global HTTP batch endpoints because we're using https://www.googleapis.com/batch/calendar/v3 无关。

这是我正在尝试做的一个例子:

https://www.googleapis.com/batch/calendar/v3
Authorization: Bearer your_auth_token
Content-Type: multipart/mixed; boundary=batch_google_calendar

--batch_google_calendar
Content-Type: application/http
Content-ID: <item-0-batchevent@example.com>

POST calendar/v3/calendars/your_calendar_id@group.calendar.google.com/events
Content-Type: application/json

{"summary":"batch API test","start":{"date":"2020-07-31"},"end":{"date":"2020-07-31"}}
--batch_google_calendar--

响应是:

--batch_3J6sfuPtVQbjZLcpUe06245gKlO31YnC
Content-Type: application/http
Content-ID: <response-item-0-batchevent@example.com>

HTTP/1.1 404 Not Found
Vary: Origin
Vary: X-Origin
Vary: Referer
Content-Type: application/json; charset=UTF-8

[{
  "error": {
    "code": 404,
    "message": "URL path: /v3/calendars/your_calendar_id@group.calendar.google.com/events could not be resolved. Maybe there is an error parsing the batch item.",
    "status": "NOT_FOUND"
  }
}
]
--batch_3J6sfuPtVQbjZLcpUe06245gKlO31YnC--

下面是一个有效的个人请求示例:

https://www.googleapis.com/calendar/v3/calendars/your_calendar_id@group.calendar.google.com/events
Authorization: Bearer your_auth_token
Content-Type: application/json

{"summary":"API test","start":{"date":"2020-07-31"},"end":{"date":"2020-07-31"}}

为什么单个请求成功,但批量请求失败?

Google 通过他们的问题跟踪器给出了一个有用的回复:在我的应用程序中批输入路径的特定方式存在错误。这在上周之前一直没有错误,所以我认为他们最后一定发生了一些变化,以降低对错误的容忍度。

我们犯的错误是在每个批次条目中省略了路径中的前导斜杠。这是我们正在做的事情:

POST calendar/v3/calendars/your_calendar_id@group.calendar.google.com/events

这是我们应该做的:

POST /calendar/v3/calendars/your_calendar_id@group.calendar.google.com/events

我希望这对遇到类似情况的其他人有所帮助!