我可以在不发送通知的情况下删除谷歌日历中的一系列事件吗



我一直在使用此代码从谷歌日历中删除事件

var fromDate = new Date(2013,0,1,0,0,0);
var toDate = new Date(2013,0,4,0,0,0);
var calendarName = 'My Calendar';
// delete from Jan 1 to end of Jan 4, 2013
var calendar = CalendarApp.getCalendarsByName(calendarName)[0];
var events = calendar.getEvents(fromDate, toDate);
for(var i=0; i<events.length;i++){
var ev = events[i];
Logger.log(ev.getTitle()); // show event name in log
ev.deleteEvent();
}

但如果我参加了一系列活动,它会向组织者发送一封电子邮件,说我拒绝了活动。我可以关闭此通知吗?

问题:

您可以通过UI修改通知设置,特别是禁用已取消事件的通知,方法是选择设置和共享,并在其他通知中将Canceled events设置为None

如果我正确理解你的话,你想用应用程序脚本以编程的方式完成这项工作。

解决方案:

据我所知,没有内置的Apps Script方法来管理这些设置。因此,您应该启用高级日历服务并使用日历API方法。

在日历API中,通知由CalendarList资源中的属性notificationSettings管理。要更改这些设置,您必须使用CalendarList:patch方法,您可以使用该方法更新现有日历。

代码示例:

function disableNotifications() {
var calendarId = "your-calendar-id";
var resource = {
notificationSettings: {
notifications: [
{
type: "eventCreation",
method: "email"
},
{
type: "eventChange",
method: "email"
}
]
}
}
Calendar.CalendarList.patch(resource, calendarId);
}

注:

  • 例如,上面的示例将禁用除eventCreationeventChange之外的此日历的所有通知类型。您可以通过添加或删除类型(以下是可能的类型(使其适应您的偏好

参考:

  • 日历API:通知
  • 高级日历服务
  • 日历列表:通知设置
  • 日历列表:补丁

最新更新