简体   繁体   中英

Google Script: How to get Recurring Events from Google Calendar?

There's a popular script on various websites that allows one to easily export Google Calendar events to a Google Spreadsheet. It works fine ... except that it does not work with recurring events.

Here's the crux of the code:

var mycal = "sample@gmail.com";
var cal = CalendarApp.getCalendarById(mycal);
var events = cal.getEvents(new Date(startDate), new Date(endDate));

Then one just needs to iterate through the members of 'events'. The problem appears to be that recurring events are defined in another way which 'getEvents' does not understand. Thus a query of a date range containing only recurring events finds nothing.

I'm wondering if anyone has written some code that would properly query for recurring events?

Robert

Your assumption is not correct, recurring events are returned exactly as any other ones.

I don't know what script you use but if you can't get the recurring events then I guess this script is just not good.

I'm not going to publish the whole code here because the version I use is a bit long but you can make a copy of this spreadsheet and test it yourself.

https://docs.google.com/spreadsheets/d/1h0uAYz7fAChbnhIfWwy-xYluomDsfkqblBRHcGNwThY/edit?usp=sharing

Run opOpen once from the menu to get the authorization then use the spreadsheet menu. You'll get a UI that will ask you to define which calendar to use and the start / end dates. These values will be stored in properties for next usage.

Serge, you're correct, it does handle recurring deliveries. My failure was to include the start time and end time in addition to the date. Once I did that, via a simple string concatenation, then all worked properly.

Thank you for your feedback!

Robert

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM