I am building a app with Firebase Functions as a backend. The app schedules events for a small sports club but those events must also be synced to a Google Calendar for public usage. I would like to keep the Google Calendar updated via a function, and thus far I have this code:
async function updateCalendarOnTimesChange(timeId: string, data: DocumentData | null) {
const authClient = await getAuthClient();
google.options({ auth: #SOMETHING# });
// Remove event from calendar to start with
await calendar.events.delete({
calendarId: calendarId,
eventId: timeId,
});
if (!data) {
return;
}
const eventTime = data.dateAndTime as Timestamp;
const dateStart = eventTime.toDate();
dateStart.setHours(data.timeStartHour);
dateStart.setMinutes(data.timeStartMinutes);
const dateEnd = eventTime.toDate();
dateEnd.setHours(data.timeEndHour);
dateEnd.setMinutes(data.timeEndMinutes);
const event = {
summary: data.description,
start: {
dateTime: dateStart,
//timeZone: 'America/Los_Angeles',
},
end: {
dateTime: dateEnd,
//timeZone: 'America/Los_Angeles',
},
};
// Create new event
const response = await calendar.events.insert({
calendarId: calendarId,
requestBody: event,
});
}
I do not know what to give the auth parameter? As it is a function that runs automaticly and not tied to the actual user creating the event, but tied to the sports club Google Calendar, how do I authenticate with the Google Calendar?
Am I on the right track here?
Thank you
Søren
I am building a app with Firebase Functions as a backend. The app schedules events for a small sports club but those events must also be synced to a Google Calendar for public usage. I would like to keep the Google Calendar updated via a function, and thus far I have this code:
async function updateCalendarOnTimesChange(timeId: string, data: DocumentData | null) {
const authClient = await getAuthClient();
google.options({ auth: #SOMETHING# });
// Remove event from calendar to start with
await calendar.events.delete({
calendarId: calendarId,
eventId: timeId,
});
if (!data) {
return;
}
const eventTime = data.dateAndTime as Timestamp;
const dateStart = eventTime.toDate();
dateStart.setHours(data.timeStartHour);
dateStart.setMinutes(data.timeStartMinutes);
const dateEnd = eventTime.toDate();
dateEnd.setHours(data.timeEndHour);
dateEnd.setMinutes(data.timeEndMinutes);
const event = {
summary: data.description,
start: {
dateTime: dateStart,
//timeZone: 'America/Los_Angeles',
},
end: {
dateTime: dateEnd,
//timeZone: 'America/Los_Angeles',
},
};
// Create new event
const response = await calendar.events.insert({
calendarId: calendarId,
requestBody: event,
});
}
I do not know what to give the auth parameter? As it is a function that runs automaticly and not tied to the actual user creating the event, but tied to the sports club Google Calendar, how do I authenticate with the Google Calendar?
Am I on the right track here?
Thank you
Søren
1 Answer
Reset to default 0I came across the article 'Integrating Firebase Cloud Functions with Google Calendar API,' which you might find helpful as an alternative for your use case, considering DazWilkin mentioned it's somewhat complicated. While the article is outdated, some developers still find it useful. It can provide you with insights into the process of connecting the two platforms.
{foo}@{project}.iam.gserviceaccount
) to the Calendar as a user with permissions to make changes to events. – DazWilkin Commented Mar 11 at 15:48