Change Google Calendar Event Free/Busy with Calendar API

非 Y 不嫁゛ 提交于 2020-03-22 10:32:42

问题


I have a GAS web app for reserving rooms. When the app creates the event, it currently defaults to "Busy" for the event. I am trying to set the default to "Free".

I found a GAS forum entry that recommends using the Advanced Google Calendar API to edit the transparency field (Source: https://code.google.com/p/google-apps-script-issues/issues/detail?id=2341).

The script they suggested was

var changes = {
transparency: "transparent"
};
Calendar.Events.patch(changes, cal_id, event_id);

I have the Advanced API enabled, but for some reason I am getting an uncaught error prompt in the Chrome console when the function executes. Any thoughts on where this error is coming from?


回答1:


After looking around, the following seems to work. I forgot that you need to remove the "@google.com" from the event ID returned by CalendarApp before making a request to CalendarApi. The calendarId can be set to 'primary' since the user is only editing an event on their own calendar

var eventId= event_id.slice(0,event_id.length-11);
var calendarId = 'primary';
Logger.log(eventId)
var changes = {
    transparency: "transparent"
  };
Calendar.Events.patch(changes,calendarId,eventId);


来源:https://stackoverflow.com/questions/42538997/change-google-calendar-event-free-busy-with-calendar-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!