How to create a two-day AllDay event using Google Apps Script?

I want to use Google Apps Script createAllDayEvent(title, date) to create a Google Calendar all day long, but there is only one date parameter, so I can only create one AllDay Google Calendar day.

Now I need to create a two-day Google AllDay calendar (for example: from June 28, 2013 to June 29, 2013), how could I do this?

Thanks for the help!

+4
source share
2 answers

You need to use createAllDayEventSeries () , which accepts Recurrence .

 var recurrence = CalendarApp.newRecurrence().addDailyRule().times(2); var eventSeries = CalendarApp.getDefaultCalendar().createAllDayEventSeries('My All Day Event', new Date('June 28, 2013'), recurrence, {guests: ' everyone@example.com '}); Logger.log('Event Series ID: ' + eventSeries.getId()); 
+3
source

You cannot add a multi-day, all-season event that spans several days through the CalendarApp class. You must do this using the calendar API through the advanced Google services.

1) Enable the calendar API for the script On the google scripts page, go to the menu item "Resources" → "Google Advanced Services". Enable the calendar API (currently v3).

2) Enable the service through the Google API Console On the "Advanced Google Services" page, click on the link to the API console. Click "+ Enable API." Select the Calendar API, then enable it.

3) Use the code snippet below (which creates a two-day gap, an all-day event) as an example

 var calId = '##########################@group.calendar.google.com'; var event = { "summary":"Summary", "location":"Location", "description":"Description", "start":{ "date":"2017-06-03" }, "end":{ "date":"2017-06-05" } }; Calendar.Events.insert(event,calId); // You can check how the events are stored below var events = Calendar.Events.list(calId, {timeMin: (new Date(2017,5,2)).toISOString(), timeMax: (new Date(2017,5,10)).toISOString(), maxResults: 2500}); 

You will notice that the above code will generate an event throughout the day from June 3 to June 4 (the end date is essentially 2017-06-05T00: 00: 00).

There are other event properties that you can add, some documented on the Calendar API / Events / insert page. Using Calendar.Events.list to get a list of events will give you an idea.

If you look at calendar API events, you will notice that there are many matches to the iCal specification.

0
source

Source: https://habr.com/ru/post/1489045/


All Articles