google-apps-script - 有没有办法通过 Google Apps 脚本修改实时日历事件?

标签 google-apps-script google-apps

目标:通过 Google 日历添加与会者添加到现场创建的实时事件

上下文:正在创建现场事件(左)+ 日历添加(右)

Live Event being created (left)+ Calendar Add on (Right)

代码片段:

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",
      ...
    }
  }
}

最佳答案

将代码更改为:

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

  CardService.newCalendarEventActionResponseBuilder()
    .addAttendees(["<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="badfc2dbd7cad6df8bfadfc2dbd7cad6df94d9d5d7" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5f3a273e322f333a6d1f3a273e322f333a713c3032" rel="noreferrer noopener nofollow">[email protected]</a>"])
    .build();

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

关于google-apps-script - 有没有办法通过 Google Apps 脚本修改实时日历事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67323077/

相关文章:

google-apps-script - 添加新日历事件时的 Google Apps 脚本和触发器

authentication - 以 Google Apps super 管理员身份通过 API 为用户关闭两步验证

java - 执行成功,但没有结果?

javascript - 谷歌脚本: get values from input forms

debugging - 如何在 GAS 中测试触发功能?

google-app-engine - Google Apps 不再免费,Google App Engine 上的自定义域

google-apps - 迄今为止的 Google 表格查询字符串

javascript - 使用谷歌应用程序脚本获取电子表格中一列的值

google-apps-script - Google 表格图表中的标题

javascript - Google 脚本错误 - UrlFetchApp 与 Facebook Graph Api 带来许多 urlfetch