【问题标题】:Batch request in Google Calendar V3 REST APIGoogle Calendar V3 REST API 中的批处理请求
【发布时间】:2021-07-20 03:40:48
【问题描述】:
【问题讨论】:
标签:
http
rest
google-api
google-calendar-api
gdata-api
【解决方案1】:
我发现外层网址一定是“https://www.googleapis.com/batch/calendar/v3/”
并且边界 url 必须是 "/calendar/v3/calendars/{calendarID}/events"
完整的 HTTP 请求如下所示:
POST /batch/calendar/v3 HTTP/1.1
Authorization: /*Auth token*/
Host: host
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length
--batch_foobarbaz
Content-ID: 1
GET /calendar/v3/calendars/{calendarID1}/events
--batch_foobarbaz
Content-ID: 2
GET /calendar/v3/calendars/{calendarID2}/events
--batch_foobarbaz--
【讨论】:
-
有人可以向我解释一下,如何使用 AJAX 进行设置吗?通常我们一次发送一个 AJAX 请求,所以我知道 Post 请求 url 是googleapis.com/batch/calendar/v3,但是 GET 请求是做什么的呢?在我们创建 POST 请求之后,这些是为了将事件从 Google 日历获取到我们的应用程序中吗?对不起,我有点困惑。
【解决方案2】:
以下批处理请求,获取 eventId1,更新 eventId2 并在以 calendarId 标识的日历下创建一个新事件。
POST /batch HTTP/1.1
Authorization: /*Auth token*/
Host: host
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length
--batch_foobarbaz
Content-Type: application/http
Content-ID: <item1:x@barnyard.example.com>
GET /calendar/v3/calendars/calendarId/events/eventId1
--batch_foobarbaz
Content-Type: application/http
Content-ID: <item2:x@barnyard.example.com>
PUT /calendar/v3/calendars/calendarId/events/eventId2
Content-Type: application/json
Content-Length: part_content_length
{{ body }}
--batch_foobarbaz
Content-Type: application/http
Content-ID: <item3:x@barnyard.example.com>
POST /calendar/v3/calendars/calendarId/events
Content-Type: application/json
Content-Length: part_content_length
{{ body }}
--batch_foobarbaz--