Google 日历 JavaScript api,将用户添加到具有 "write" 访问权限的日历

Google Calendar JavaScript api, add user to a calendar with "write" access

我正在开发一个与 Google 日历相关的网站。本网站使用 Google 的 JavaScript API 检索 public 日历的事件并将其呈现在网站上。我现在可以创建新事件、更新事件和从我的站点中删除事件,并且可以毫无问题地在 Google 日历中进行更新。

如果我能够编辑此日历信息是因为我的 Google 帐户对此特定日历具有 read/write 权限。

我的问题:有没有办法使用 JavaScript API 将用户添加到对该日历具有写入权限的帐户列表?显然我不想在日历设置页面上手动添加每个帐户的电子邮件。

我能做什么?我是否需要插入 ACL 规则(JavaScript 没有太多关于此的文档)或类似的东西?

使用 Acl: insert 您可以添加具有 "writer" 或 "owner" 权限的用户,这将授予用户对您的日历的读写权限。

The role assigned to the scope. Possible values are:

  • "none" - Provides no access.
  • "freeBusyReader" - Provides read access to free/busy information.
  • "reader" - Provides read access to the calendar. Private events will appear to users with reader access, but event details will be hidden.
  • "writer" - Provides read and write access to the calendar. Private events will appear to users with writer access, and event details will be visible.
  • "owner" - Provides ownership of the calendar. This role has all of the permissions of the writer role with the additional ability to see and manipulate ACLs.

使用同一页面上的 API 资源管理器,我能够成功发出此请求:

POST https://www.googleapis.com/calendar/v3/calendars/12345@group.calendar.google.com/acl?key={YOUR_API_KEY}

{
 "role": "writer",
 "scope": {
  "type": "user",
  "value": "user@example.com"
 }
}

您可以像这样将它与 Google API Javascript 客户端一起使用:

var calendarid = "12345@group.calendar.google.com";
var req = {
  "calendarId": calendarid,
  "resource": {
    "role": "writer",
    "scope": {
      "type": "user",
      "value": "user@example.com"
    }
  }
}
var request = gapi.client.calendar.acl.insert(req);
request.execute(function(resp) {
  console.log(resp);
});