slanton
slanton

Reputation: 71

Google Apps Script -Advanced Calendar Service

I want to share a google Sheet with users that allows them to add a multi all-day event to their calendar. As google doesnt provide a function to do that I have tired various workarounds. The createEvent(title, startTime, endTime) isnt perfect as it uses and shows datetime, createEventFromDescription(description) doesnt allow meta data such as description and so I have tried using the Advanced Calendar Service. From what I have read once you have enabled the Advanced Calendar Service you should be able to use the Google Calendar API as if you were using the App Script's built-in Calendar Service . If I run this built-in function in a sheets script editor it works and I can make a copy of the sheet, email it to someone else and they can also run the function
var event = CalendarApp.getDefaultCalendar().createEvent('Apollo 11 Landing', new Date('July 20, 1969 20:00:00 UTC'), new Date('July 20, 1969 21:00:00 UTC'), {location: 'The Moon'}); Logger.log('Event ID: ' + event.getId());
If I use the Advanced Calendar Service and use the code below which is basically their example, I can run the function in the Script Editor and it works but if I make a copy of the sheet and email it to someone else to try I get the error "Project (number) is not found and cannot be used for API calls" . Can anyone see what I am doing wrong.

function createEvent() {
var calendarId = 'primary';

var event = {
summary: 'Lunch Meeting',
location: 'The Deli',
description: 'To discuss our plans for the presentation next week.',
start: {
  date: "2017-05-21"
},
end: {
  date: "2017-05-24"
},
attendees: [
  {email: '[email protected]'},
  {email: '[email protected]'}
],
// Red background. Use Calendar.Colors.get() for the full list.
colorId: 11
};
event = Calendar.Events.insert(event, calendarId);
Logger.log('Event ID: ' + event.getId());
}

Upvotes: 1

Views: 1420

Answers (1)

Joshua Dawson
Joshua Dawson

Reputation: 629

Hmm, I don't know why you're getting the API call error; however, createEventFromDescription returns an event object, so you could add a description like so:

var event = createEventFromDescription("Some event 4/25 - 4/30");
event.setDescription("This is a description.");

The CalendarApp isn't as robust as the Advanced Calendar Service (for example you can't set an events color), but it might suit your purposes enough to get by.

Upvotes: 0

Related Questions