Background: Google Calendar > click New button > enter New Event Page > Add Conference
Question: When user click Add Conference to schedule a conference(3rd party service, not Hangouts), how could I get the current event's conference data? I tried to use Calendar.Events.get
API but it returned 404.
my appscripts setting is here:
when user schedule a conference, it will trigger
onCalendarEventUpdate
function
{
"timeZone": "America/Los_Angeles",
"addOns": {
"calendar": {
"eventUpdateTrigger": {
"runFunction": "onCalendarEventUpdate"
},
}
}
}
my onCalendarEventUpdate
:
function onCalendarEventUpdate(context: any) {
// I can get calendarId, evnetId
const {
calendar: { calendarId, id: evnetId }
} = context;
// when I try to get event conferenceData, it returns 404
let event;
try {
event = Calendar.Events && Calendar.Events.get(calendarId, evnetId);
if (!event) {
Logger.log(`[getEventsCollectionByCalendarId]event not found`);
}
} catch (e) {
Logger.log(`[getEventsCollectionByCalendarId]error: ${JSON.stringify(e)}`);
}
}
now the error message is:
{
"message":"API call to calendar.events.get failed with error: Not Found",
"name":"GoogleJsonResponseException",
"lineNumber":64,
"details":{
"message":"Not Found",
"code":404,
"errors":[{
"domain":"global",
"reason":"notFound",
"message":"Not Found"
}]
}
}
Based on the error message, I would guess your calendarId and eventId are invalid. The event updated event does not give you the event id sadly. Because of this, you need to perform an incremental sync to get the updated event data, which means you need to do an initial sync first as described in the docs (link below).
First, run this code to perform the initial sync and get the nextSyncTokens for each calendar. You only need to run this once.
Then, set your trigger to run this function and log the conference data. Notice we also update the nextSyncToken so the next execution will work correctly.
Link to relevant docs:
https://developers.google.com/apps-script/guides/triggers/events#google_calendar_events