Reputation: 679
I am currently building a Google Site for the branch of the company I work for. As part of this site, we have a page hosting a web app that upon accessing grabs the current user's ID and uses javascript to generate custom page content including things such as the individual's holiday and uniform requests.
As part of this page, we would also like to display the user's own primary calendar in the page. I am aware of how to embed calendars within the web app, however, I am struggling with finding a way to call the user's own calendar.
Is there a way of doing this based on their userID, or would I need to gather all of their calendar Id's and then consult our database for the individual's calendar Id when they load the page in order to embed it?
All thoughts are appreciated.
Upvotes: 1
Views: 121
Reputation: 17613
Since you want to get the user's calendar, you can do this using:
getAllOwnedCalendars() - Gets all calendars that the user owns.
// Determines how many calendars the user owns.
var calendars = CalendarApp.getAllOwnedCalendars();
Logger.log('This user owns %s calendars.', calendars.length);
getCalendarById(id) Gets the calendar with the given ID.
// Gets the public calendar "US Holidays" by ID.
var calendar = CalendarApp.getCalendarById(
'en.usa#[email protected]');
Logger.log('The calendar is named "%s".', calendar.getName());
getCalendarsByName(name) Gets all calendars with a given name that the user owns or is subscribed to. Names are not case-sensitive.
// Gets the public calendar named "US Holidays".
var calendars = CalendarApp.getCalendarsByName('US Holidays');
Logger.log('Found %s matching calendars.', calendars.length);
Upvotes: 1