Google Apps脚本:如何检查日历事件是否已标记为手动删除 [英] Google Apps Script: How to check if a calendar event has been marked as deleted manually

查看:68
本文介绍了Google Apps脚本:如何检查日历事件是否已标记为手动删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个Google Apps脚本,该脚本将电子表格中保存的事件添加到了Google日历中.每个事件都存储日历事件的ID,以便在电子表格中的事件被修改后可以对其进行更新.仍然可以在日历中手动删除该事件,因此我希望脚本检测到该事件并重新创建该事件.不幸的是,在getEventById(...)时,我不能简单地检查 null /reference/calendar/calendar"rel =" nofollow noreferrer> calendar 对象,因为即使将其删除,该函数似乎仍会返回有效的 calendar 对象.

I've written a Google Apps Script which adds events kept in a spreadsheet to a google calendar. Each event stores the calendar event's ID so that it can update it if the event in the spreadsheet gets modified. The event can still be deleted manually in the calendar so I would like the script to detect this and recreate the event. Unfortunately, I cannot simply check for null when calling getEventById(...) on a calendar object because even when deleted, this function seems to be returning a valid calendar object.

CalendarEvent API文档似乎没有指向检查事件是否已通过UI/手动删除的方法.是否可以通过Google Apps API访问此属性?

The CalendarEvent API documentation doesn't seem to point to a way to check if the event has been deleted via the UI/manually. Is there a way of accessing this property through the Google Apps API?

即使永久删除已删除事件也不能解决问题,尽管这样可以防止修改返回的 event 对象.

Even permanently deleting trashed events does not fix the problem, although it then prevents modifications to the returned event object.

我可以使用什么来检查事件(仍然存在)是否已被删除"?我唯一想到的可能是 CalendarEvent 对象的 get/setTag()方法.

What can I use to check if the event (which still exists) has been "deleted"? The only thing I can think might be of use is the get/setTag() methods for the CalendarEvent object.

或者,这个问题看起来很相似,但是感觉像最好是比搜索一系列垃圾事件更好的方法,而且我不确定这是否会解决让ID字符串返回已永久"删除的有效事件的问题.

Alternatively, this question looks similar, but it feels like there should be a better way than searching through a list of trashed events, and I'm not sure this would get around the issue of having ID strings return valid events that have been "permanently" deleted.

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
}

推荐答案

我花了很多时间解决这个问题,我无法理解为什么没有更好的方法直接通过CalendarApp解决.您需要的是这样:

I have spent quite a time solving this and I cant udnerstand why there is no better way how to solve it, directly by CalendarApp. What you need is this:

var eventId = "5qif5n15v46c0jt5gq20a39dqu@google.com".split("@")[0];
if(Calendar.Events.get("yourCalendarId", eventId).status === "cancelled")
        CODE://what to do if event was deleted (manually)

注意:

  1. 由于API v3.0仅将@之前的部分用作eventid,因此您需要分裂(休息)
  2. 您需要首先激活Calendar API v3.0.

您将找到有关此问题的更多信息:检查Google日历事件的存在性

You will find more info about in this question: Checking a Google Calendar Event's Existence

这篇关于Google Apps脚本:如何检查日历事件是否已标记为手动删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆