Reputation: 37
So I have integrated Fullcalendar on my site, which works fine. I have also integrated it to have events from my Google Calendar. This works when the calendar is set to public for everyone, which is not a desirable option. I know there is a way to share the events with the secret key, but I don't get it to work with the calendar.
Here is the render script of the calendar:
<script>
$(document).ready(() => {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,listYear'
},
displayEventTime: false, // don't show the time column in list view
// THIS KEY WON'T WORK IN PRODUCTION!!!
// To make your own Google API key, follow the directions here:
// http://fullcalendar.io/docs/google_calendar/
googleCalendarApiKey: 'API_KEY_HERE',
events: '[email protected]',
eventClick: function(arg) {
// opens events in a popup window
window.open(arg.event.url, 'google-calendar-event', 'width=700,height=600');
arg.jsEvent.preventDefault() // don't navigate in main tab
},
loading: function(bool) {
document.getElementById('loading').style.display =
bool ? 'block' : 'none';
}
});
calendar.render();
});
</script>
Google Calendar secret is in this format.
https://calendar.google.com/calendar/ical/CALENDAR_ID_HERE%40group.calendar.google.com/private-PRIVATE_KEY_HERE/basic.ics
Is there way to format this address in the script so I could show events that are not publically shared?
Upvotes: 1
Views: 869
Reputation: 116948
Api keys are used to access public data, they do not work with private data. An api key should also only be giving you read access you will not be able to write to that calendar. So no there is no way to use an api key with a privately own google calendar.
You have two options the first being using Oauth2 and requesting authorization of the owner of the calendar. This will give you an access token which will allow for read and write access to the users calendar.
The second option would be to use a service account, this will only work with google workspace and will require that the admin of your workspace account configure domain wide dedication to the service account granting it access to preform actions on behalf of the workspace user who owns the calendar. This will again give you read write access on the calendar.
Upvotes: 2