Software Engineer
Software Engineer

Reputation: 31

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 = "[email protected]";
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

Upvotes: 1

Views: 1432

Answers (2)

Software Engineer
Software Engineer

Reputation: 31

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

Upvotes: 0

Serge insas
Serge insas

Reputation: 46794

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.

Upvotes: 1

Related Questions