ink*_*ris 5 javascript google-calendar-api google-apps-script
我编写了一个 Google Apps 脚本,它将电子表格中保存的事件添加到谷歌日历中。每个事件都会存储日历事件的 ID,以便在电子表格中的事件发生修改时可以更新它。该事件仍然可以在日历中手动删除,因此我希望脚本能够检测到这一点并重新创建该事件。不幸的是,我不能简单地检查null何时调用getEventById(...)对象calendar,因为即使删除后,该函数似乎也会返回有效的calendar对象。
APICalendarEvent文档似乎没有指出一种方法来检查事件是否已通过 UI/手动删除。有没有办法通过 Google Apps API 访问此属性?
即使永久删除垃圾事件也不能解决问题,尽管它可以防止对返回的event对象进行修改。
我可以用什么来检查事件(仍然存在)是否已被“删除”?我认为唯一可能有用的是对象get/setTag()的方法CalendarEvent。
或者,这个问题看起来很相似,但感觉应该有一种比搜索废弃事件列表更好的方法,而且我不确定这是否可以解决让 ID 字符串返回“永久”的有效事件的问题。 ”删除了。
var calendarId = "abc123@group.calendar.google.com"
var calendar = CalendarApp.getCalendarById(calendarId);
var event = calendar.createEvent(...);
// Event is then deleted manually in calendar but
// ID has been saved in spreadsheet (or elsewhere)
if (calendar.getEventById("the-deleted-event-id") == null) {
// Create the event (This is never reached)
} else {
// Update the event
}
Run Code Online (Sandbox Code Playgroud)
我花了很长时间解决这个问题,但我无法理解为什么没有更好的方法直接通过 CalendarApp 来解决它。你需要的是这样的:
var eventId = "5qif5n15v46c0jt5gq20a39dqu@google.com".split("@")[0];
if(Calendar.Events.get("yourCalendarId", eventId).status === "cancelled")
CODE://what to do if event was deleted (manually)
Run Code Online (Sandbox Code Playgroud)
笔记:
您将在这个问题中找到更多信息:Checking a Google Calendar Event's Existence