_docs-v5/event-source/google-calendar.md
FullCalendar can display events from a public Google Calendar.<!--more--> Google Calendar can serve as a backend that manages and persistently stores event data (a feature that FullCalendar currently lacks).
You must first have a Google Calendar API Key:
Make your Google Calendar public:
Obtain your Google Calendar's ID:
You must include the google-calendar plugin. If you are using an ES6 build system then do something like this:
import { Calendar } from '@fullcalendar/core';
import googleCalendarPlugin from '@fullcalendar/google-calendar';
...
let calendar = new Calendar(calendarEl, {
plugins: [ googleCalendarPlugin ]
});
Alternatively, you can use a global bundle:
<link href='fullcalendar/main.css' rel='stylesheet' />
<script src='fullcalendar/main.js'></script>
<script>
...
var calendar = new FullCalendar.Calendar(calendarEl, {
// no plugin config required!
});
...
</script>
Now it's time to initialize your calendar in JavaScript. This is the most minimal example:
let calendar = new Calendar(calendarEl, {
plugins: [ googleCalendarPlugin ],
googleCalendarApiKey: '<YOUR API KEY>',
events: {
googleCalendarId: '[email protected]'
}
});
If you want to specify some Event Source options, you can include them in the events object:
let calendar = new Calendar(calendarEl, {
plugins: [ googleCalendarPlugin ],
googleCalendarApiKey: '<YOUR API KEY>',
events: {
googleCalendarId: '[email protected]',
className: 'gcal-event' // an option!
}
});
View a demo that displays US holidays from Google Calendar.
You can specify multiple Google Calendars by using the eventSources option:
<script type='text/javascript'>
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
googleCalendarApiKey: '<YOUR API KEY>',
eventSources: [
{
googleCalendarId: '[email protected]'
},
{
googleCalendarId: '[email protected]',
className: 'nice-event'
}
]
});
calendar.render();
});
</script>
Google Calendar's API allows you to specify Extended Properties for your events. The extended properties will be available in the extendedProps hash of each Event Object.
If you need different API keys per calendar, you can set a googleCalendarApiKey option on each individual Event Source when written in extended form.
For detecting errors, use the Event Source Object's failure callback.