最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to delete an event with google apps script and sending an Email - Stack Overflow

programmeradmin0浏览0评论
 function modifyevent(eventid,cal){
  var event = cal.getEventById(eventid);
  event.deleteEvent();
 }

This is working but not sending an email. Do you have an another way to do it with GOOGLE apps script. I would like to delete the event and send an email to attendees which is gonna delete the event from their calendar even if they are using a calendar such as outlook.

This is how I create the event if it can help:

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]});
}
 function modifyevent(eventid,cal){
  var event = cal.getEventById(eventid);
  event.deleteEvent();
 }

This is working but not sending an email. Do you have an another way to do it with GOOGLE apps script. I would like to delete the event and send an email to attendees which is gonna delete the event from their calendar even if they are using a calendar such as outlook.

This is how I create the event if it can help:

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]});
}
Share Improve this question edited Apr 12, 2018 at 15:23 boxb asked Apr 12, 2018 at 10:28 boxbboxb 431 silver badge8 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

In Script Editor, go to 'View' - 'Show manifest file'. In 'appscript.json', add the following scopes:

 "oauthScopes": ["https://www.googleapis./auth/calendar",             
   "https://www.googleapis./auth/script.external_request"]

Go to 'Resources -> 'Cloud Platform Project'. Click on your project name to open project page on GCP. Type 'Calendar API' in the search box at the top of the page. Click "Enable" on the Calendar API page.

Finally, use UrlFetchApp to call the Calendar API endpoint. One thing to note is that you need to modify the string returned by CalendarEvent.getId() to get the actual identifier without the '@google.' part. I've tested the code below - everything works perfectly, including notifications.

 function deleteEvent(eventId) {

 var baseUrl = "https://www.googleapis./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);    


}

You can use the GmailApp.sendEmail(String,String,String) method (or MailApp.sendEmail(String,String,String) method, depending of your needs), like:

function modifyevent(eventid,cal){
  var event = cal.getEventById(eventid);
  var name = event.getTitle();
  event.deleteEvent();
  GmailApp.sendEmail("[email protected]", "Event deleted", "The event " + name + " has been deleted on " + now.toString());
}
发布评论

评论列表(0)

  1. 暂无评论