9

I made a working bound script in a clone of my original Google Spreadsheet, put together over a course of several days.

I then copied my formula to a new spreadsheet.

Suddenly, even though I don't think I made any changes to any relevant code, I'm seeing "reference error: "Calendar" is not defined google API."

I have a lot of code so it would be difficult to paste it all, but the relevant section is here:

var start = (passed as argument to function);
  var end = (passed as argument to function);
  var calendarId = 'redacted'//source calendar 
  var optionalArgs = {
    timeMin: start.toISOString(),
    timeMax: end.toISOString(),
    showDeleted: false,
    singleEvents: true,
    maxResults: null,
    orderBy: 'startTime'
  };
  var response = Calendar.Events.list(calendarId, optionalArgs);
Dr.Queso
  • 761
  • 2
  • 6
  • 11

1 Answers1

40

This took me way too long to get through, so dear person of the future, if I've saved you a few minutes, my struggles will be worthwhile.

Calendar API has to be turned on for Calendar.Events.list to work.

In your script's menu, select "Resources" then "Advanced Google Services." You will see a list of APIs with switches.

To use the API for another service, you must turn it on both here and in your Google Developers Console (just follow the link at the bottom of the dialogue window).

Also, I had sort of assumed that in the Google Developers Console, once an API was turned on, it was turned on for you as a user, but there is a unique console for each project, which is what you're taken to when you follow the link. You have to turn it on again for each additional project.

Dr.Queso
  • 761
  • 2
  • 6
  • 11
  • 3
    Thank you @dr.queso! I am person from the future. Coming here to say you saved me hours of trial and error. These days the interface is a bit different. You have to click Services and add the "Google Calendar API" option. Thanks again! – TimmyGee Jul 01 '21 at 13:35