Batch request in Google Calendar V3 REST API

假装没事ソ 提交于 2019-12-23 09:04:07

问题


How to get/add/update Google Calendar Events using batch request through V3 REST API? I've tried and but not works. According to the docs (https://developers.google.com/google-apps/calendar/batch) it should be possible to send a batch request by posting a multipart/mixed content type message to the API. An example of a working HTTP POST would be great.

Thanks, Riyaz


回答1:


The following batch request, gets the eventId1, updates the eventId2 and creates a new event under calender that is identified with 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--



回答2:


The endpoint is

https://www.googleapis.com/batch

That works for me when I do Calendar batch requests. One problem I had was with my last boundary token I didn't have the -- after it. So each token starts with -- and the last one has -- at the end. As @Burcu Dogan's example shows.



来源:https://stackoverflow.com/questions/17425934/batch-request-in-google-calendar-v3-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!