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

function modifyevent(eventid,cal){var event = cal.getEventById(eventid);event.deleteEvent();}This is wor

 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());
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744466088a4575524.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信