function modifyevent(eventid,cal){
var event = cal.getEventById(eventid);
event.deleteEvent();
}
这是可行的,但不能发送电子邮件。您是否有使用 GOOGLE 应用程序脚本 的另一种方法。我想删除该 Activity 并向与会者发送一封电子邮件,即使他们使用的是 outlook 等日历,也会从他们的日历中删除该 Activity 。
如果有帮助的话,我就是这样创建事件的:
function createEvent(date,start,end,summary,location,email,calendarId,incrementligne,ss){
var newdatestart = new Date(date.getYear(), date.getMonth(), date.getDate(), start.getHours(), start.getMinutes(), "0", "0");
var newdateend = new Date(date.getYear(), date.getMonth(), date.getDate(), end.getHours(), end.getMinutes(), "0", "0");
var invitelist = email.split(',');
var longueur = invitelist.length;
var event = {
summary:summary,
location: location,
description: '',
start: {dateTime: newdatestart.toISOString()},
end: {dateTime: newdateend.toISOString()},
attendees: [
{email: ''},{email: ''}],
// Red background. Use Calendar.Colors.get() for the full list.
colorId: 11
};
for(var i=0; i < invitelist.length;i++){
event.attendees.push({email: invitelist[i]});
}
最佳答案
在脚本编辑器中,转到“查看”-“显示 list 文件”。在“appscript.json”中,添加以下范围:
"oauthScopes": ["https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/script.external_request"]
转到“资源”->“云平台项目”。单击您的项目名称以打开 GCP 上的项目页面。在页面顶部的搜索框中键入“日历 API”。单击日历 API 页面上的“启用”。
最后,使用 UrlFetchApp 调用日历 API 端点。需要注意的一件事是,您需要修改 CalendarEvent.getId() 返回的字符串以获取不含“@google.com”部分的实际标识符。我已经测试了下面的代码 - 一切正常,包括通知。
function deleteEvent(eventId) {
var baseUrl = "https://www.googleapis.com/calendar/v3/calendars/{calendarId}/events/{eventId}?sendNotifications=true";
var calendarId = CalendarApp.getDefaultCalendar().getId();
eventId = eventId.substr(0, eventId.indexOf("@"));
var url = baseUrl.replace("{calendarId}", calendarId).replace("{eventId}", eventId);
var options = {
"method": "DELETE",
"headers": {"Authorization":"Bearer " + ScriptApp.getOAuthToken()},
"muteHttpExceptions": true
};
var res = UrlFetchApp.fetch(url, options).getContentText();
Logger.log(res);
}
关于javascript - 如何使用谷歌应用程序脚本删除事件并发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49794213/