【问题标题】:Is there a way to modify a live Calendar event through Google Apps Script?有没有办法通过 Google Apps 脚本修改实时日历活动?
【发布时间】:2021-04-29 18:22:26
【问题描述】:

目标:通过 Google 日历添加与会者到现场创建的现场活动中

上下文:正在创建的实时事件(左)+ 日历添加(右)

代码片段:

current_user = e.calendar.calendarId;
event_id = e.calendar.id;
var calendar = CalendarApp.getCalendarById(current_user);
var event = calendar.getEventById(event_id);

但是,当我打开一个事件并且current_userevent_id 具有值时,event 似乎是null,因为这个事件在技术上还没有“创建”。如果它已经创建,那么一个简单的event.addGuest() 就可以了

是否可以在创建实时事件时对其进行自定义?我发现的每个示例都只更新已创建的事件。

编辑:忘记发布我正在使用的范围。 appsscript.json 的片段如下

{
  ....,
  "oauthScopes": [
    "https://www.googleapis.com/auth/calendar.addons.current.event.read",
    "https://www.googleapis.com/auth/calendar.addons.current.event.write",
    "https://www.googleapis.com/auth/calendar.addons.execute",
    "https://www.googleapis.com/auth/script.external_request",
    "https://www.google.com/calendar/feeds"
  ],
  "addOns": {
    "common": {
      ...
      }
    },
    "calendar": {
      "currentEventAccess": "READ_WRITE",
      ...
    }
  }
}

【问题讨论】:

  • 我不这么认为。我不会浪费我的时间。但我不确定。为什么不继续尝试,让我们知道它是否有效。
  • 它不起作用,我认为你是对的,谷歌还没有实现这样的逻辑。
  • 我认为他们不希望您与他们的代码进行任何直接交互。
  • 文档Workspace Calendar Event Objects 适合阅读此问题并希望查看文档的任何人。

标签: google-apps-script google-apps


【解决方案1】:

将您的代码更改为:

  if (!e.calendar.capabilities.canAddAttendees) {
    return;
  }

  CardService.newCalendarEventActionResponseBuilder()
    .addAttendees(["example1@example.com", "example2@example.com"])
    .build();

请参阅文档:
https://developers.google.com/workspace/add-ons/calendar/calendar-actions?hl=en#adding_attendees_with_a_callback_function

【讨论】:

  • 感谢您的解决方案。如果你不介意的话,我还有一个问题。因此,我注意到,当您查看了添加内容并添加了与会者(通过您共享的代码或手动添加)时,它实际上会刷新日历添加到主页(离开它所在的页面) .对我来说奇怪的是,目前我拥有的触发器是:“homepageTrigger”:{“runFunction”:“onHomePage_noevent”},“eventOpenTrigger”:{“runFunction”:“onHomePage”}为什么添加与会者时,“onHomePage "又弹出来了?
  • 很遗憾,我不知道您的额外问题的答案。我需要研究一下。你可以在这里问另一个问题,或者Apps Script Group
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-08-09
  • 2020-10-17
  • 2020-03-24
  • 1970-01-01
  • 2014-06-05
  • 2013-09-12
  • 2021-09-30
相关资源
最近更新 更多