我正在使用以下代碼檢查 Google 日歷中是否有取消的事件。它適用于定期的、非經常性的事件。但是,當用戶洗掉重復事件系列中的單個事件時,我遇到了問題。
function checkForCancelledEvents(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Data Source");
ss.setActiveSheet(sheet);
//sort by date added
var lastRow = sheet.getLastRow();
var range = sheet.getRange(1,2,lastRow, 5)
var values = range.getValues();
//in the array the 3 position is the eventId, the 4 position is the calendar ID, I'm putting more into the array since I was playing around with also using the start date or time to solve the problem
//loop through all using Calendar.Events.get
for (i=1;i<values.length;i ) {
var splitEventID = values[i][3].toString().split("@")[0] //remove the calendarID from the eventID
if (Calendar.Events.get(values[i][4],splitEventID).status === "cancelled") {
//the below clears the content of the row that contains the cancelled events
//the range has to start at i 1 since the values include the header row, but the for loop starts at 1 instead of 0 to prevent the API from calling with data from header row (which produces an error). So i 1 gives the accurate row number for which the cancelled event lives
var clearRange = sheet.getRange(i 1,1,1,7)
clearRange.clearContent()
} else {
//Logger.log("this is NOT cancelled")
}
}
}
問題是重復發生的事件都包含相同的 eventID 和 calendarID。它們也具有相同的 iCalUID。重復發生的事件確實有不同的id但非重復發生的事件沒有相同的id格式。我嘗試使用 Calendar.event.list 并timeMin在重復系列中添加每個事件的 ,但是該事件仍然被列為confirmed即使它被洗掉了。有沒有辦法找到重復系列中的單個事件是否已被洗掉?
uj5u.com熱心網友回復:
我相信你的目標如下。
- 從
Is there a way to find if a single event within a recurring series has been deleted?,您想知道是否使用 Google Apps 腳本洗掉了重復事件中的事件之一。
在這種情況下,我認為當使用“事件:實體”的方法時,您的目標可能能夠實作。示例腳本如下。
示例腳本:
在您使用此腳本之前,請在 Advanced Google services 中啟用 Calendar API。
var calendarId = "###"; // Please set the calendar ID.
var eventId = "###"; // Please set the event ID.
var ar = [];
var pageToken = "";
do {
var res = Calendar.Events.instances(calendarId, eventId, {maxResults: 2500, showDeleted: true, pageToken});
if (res.items.length > 0) ar = [...ar, ...res.items.filter(({status}) => status == "cancelled")];
pageToken = res.nextPageToken;
} while (pageToken);
if (ar.length > 0) {
// When "ar" has the values, the events are deleted from the recurring events.
// do something.
}
- 在上面的腳本中,您可以在 處看到已洗掉事件的資訊
ar。
筆記:
- 這是一個簡單的示例腳本。所以請根據您的實際情況修改它。
參考:
- 事件:實體
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/374821.html
上一篇:如何驗證當前登錄的帳戶是什么?
