使用 Google 日历 API 的批量请求列出多个用户的日历事件

问题描述 投票:0回答:1

我想通过批量请求获取多个用户的公共事件详细信息。

我可以通过拨打 https://www.googleapis.com/calendar/v3/calendars/[email protected]/events 来获取 1 位用户的公开活动详细信息。

但是我找不到有关日历 API 批量请求的任何文档,因此我可以一次为多个用户执行此操作。

google-calendar-api
1个回答
0
投票

我认为你的目标可以通过批量请求来实现。关于

But I can't find any documentation on a Calendar API batch request so I can do this for multiple users at one time.
,遗憾的是,现在我找不到Calendar API批量请求的官方文档。 Calendar API批量请求的官方文档旧网址是
https://developers.google.com/calendar/batch
。但不幸的是,在现阶段,这个网址似乎链接到了
https://developers.googleblog.com/2018/03/discontinuing-support-for-json-rpc-and.html

但是,我认为批量请求的请求正文的基本结构与 Drive API 的相同。 Ref1 Ref2(作者:我) 实际上,当我使用 Drive API 的相同结构测试用于从多个日历检索事件列表的示例脚本时,我确认从每个日历检索事件列表。 看来Drive API和Calendar API之间的区别是批处理路径和端点。

从您的问题来看,我猜您不需要示例脚本,并且您想知道是否可以使用批处理请求从多个日历中检索事件列表,因为没有与特定语言相关的标签。

从多个日历中检索事件列表的批量请求的简单示例请求正文如下。在本例中,事件列表是从 2 个日历中检索的。

--sampleBoundary12345
Content-Type: application/http
Content-ID: 1

GET https://www.googleapis.com/calendar/v3/calendars/{calendarId1}/events

--sampleBoundary12345
Content-Type: application/http
Content-ID: 2

GET https://www.googleapis.com/calendar/v3/calendars/{calendarId2}/events

--sampleBoundary12345--

请求该请求体时,返回以下示例结果。

--batch_###
Content-Type: application/http
Content-ID: response-1

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Vary: Origin
Vary: X-Origin
Vary: Referer

{
 "kind": "calendar#events",
 "etag": "\"###\"",
 "summary": "###",
 "description": "###",
 "updated": "###",
 "timeZone": "###",
 "accessRole": "writer",
 "defaultReminders": [],
 "nextPageToken": "###",
 "items": [,,,]
}

--batch_###
Content-Type: application/http
Content-ID: response-2

HTTP/1.1 200 OK
Vary: Origin
Content-Type: application/json; charset=UTF-8
Vary: X-Origin
Vary: Referer

{
 "kind": "calendar#events",
 "etag": "\"###\"",
 "summary": "###",
 "description": "###",
 "updated": "###",
 "timeZone": "###",
 "accessRole": "writer",
 "defaultReminders": [],
 "nextPageToken": "###",
 "items": [,,,]
}

--batch_###--

原始响应值是一个字符串值,如上面的值所示。所以,如果你想检索事件项,就需要解析它。

注:

  • 在这种情况下,作为要求前提,您需要具有从所有日历中读取事件项目的权限。请注意这一点。

  • 重要的一点是,当您想要从日历中检索事件项目时,即使使用

    maxResults=2500
    ,也只能检索 2500 个项目。如果您想检索更多事件项,则需要使用
    pageToken
    检索下一页。虽然我不确定你的实际情况,但请注意这一点。

  • 从您其他问题的标签来看,如果您想使用Google Apps Script,这个Google Apps Script库也许可以使用。 参考(作者:我)

© www.soinside.com 2019 - 2024. All rights reserved.