Reputation: 13
I want to create a script that lets me import a Google Calendar's events into a Google Sheet. I am using a standard script that successfully lets me import a Google Calendar with an ID ending in @calendar.google.com
, however I am trying to import one with the ending @import.calendar.google.com
and the same script doesn't work.
When I use a calendar with that ending as in the code below it gives me an error:
TypeError: Cannot call method "getEvents" of null.
in regards to variable cal
in the code below.
Is there a way to make it work?
var mycal = "[email protected]";
var cal = CalendarApp.getCalendarById(mycal);
var events = cal.getEvents(new Date("January 1, 2019 00:00:00 CST"), new Date("December 31, 2019 23:59:59 CST"));
Upvotes: 1
Views: 223
Reputation: 7367
Is the calendar which is failing directly shared with your user?
I had a similar issue a couple years ago and determined that calendars had to be explicitly shared with the user executing the script. Calendars which were publicly available or shared to a domain failed to be opened by CalendarApp.
Upvotes: 1