【问题标题】:Batch request in Google Calendar V3 REST APIGoogle Calendar V3 REST API 中的批处理请求
【发布时间】:2021-07-20 03:40:48
【问题描述】:

如何通过 V3 REST API 使用批处理请求获取/添加/更新 Google 日历事件?我试过了,但没有用。根据文档 (https://developers.google.com/google-apps/calendar/batch),应该可以通过向 API 发布多部分/混合内容类型消息来发送批处理请求。一个有效的 HTTP POST 的例子会很棒。

谢谢, 里亚兹

【问题讨论】:

    标签: 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--
    

    【讨论】:

    • 用于 /batch 请求的完整 url 是什么。我尝试使用“googleapis.com/batch”但失败了...请告诉我
    【解决方案3】:

    端点是

    https://www.googleapis.com/batch

    当我执行日历批处理请求时,这对我有用。我遇到的一个问题是我的最后一个边界令牌在它之后没有--。所以每个令牌都以-- 开头,最后一个以-- 结尾。正如@Burcu Dogan 的示例所示。

    【讨论】:

    猜你喜欢
    • 2013-07-24
    • 1970-01-01
    • 2015-02-01
    • 1970-01-01
    • 2016-08-04
    • 2014-07-06
    • 2013-09-05
    • 2023-02-09
    • 1970-01-01
    相关资源
    最近更新 更多