我知道日历 api 和日历的 appscript 是不同的 API 集。正如下面的问题。
GoogleAppsScript for Calendar 与 Google CalendarAPI
我正在尝试自动将谷歌表格同步到日历事件。我能够创建日历事件,但正在创建的日历事件的状态始终设置为“忙碌”。我读到您需要将透明度设置为透明才能使其不设置为繁忙。
但是谷歌日历应用程序脚本似乎没有API。有什么想法吗?
let eventDescription = `blah blah`;
let newEvent = eventCal.createAllDayEvent(eventTitle, aDateObj, {
description: eventDescription,
// Tried to add transparency but this does not do anything
transparency: "transparent"
});
newEvent.setColor(CalendarApp.EventColor.YELLOW);
let changes = {
transparency: "transparent"
};
// Saw the setting of patch but this api fails on appscripts.
//Calendar.Events.patch(changes, calendarId, newEvent.getId());
只要使用 Google Apps 脚本运行您提供的示例脚本,就会出现错误
GoogleJsonResponseException: API call to calendar.events.patch failed with error: Not Found
。
经过测试,我发现生成的
eventId
看起来像这样:
Events: patch
中接受的内容类似于示例中的 q912u95u62rndr3a631fja2edo
。
要解决此问题,您必须从脚本生成的
@google.com
中删除 eventId
。您可以通过更改来实现:
Calendar.Events.patch(changes, calendarId, newEvent.getId());
致:
Calendar.Events.patch(changes, calendarId, newEvent.getId().replace("@google.com", ""));
这是补充了缺少的变量的示例脚本:
const myFunction = () => {
let eventCal = CalendarApp.getDefaultCalendar();
let calendarId = eventCal.getId();
let eventTitle = "Test Event";
let aDateObj = new Date("September 29, 2024");
let eventDescription = `blah blah`;
let newEvent = eventCal.createAllDayEvent(eventTitle, aDateObj, { description: eventDescription }).setColor(CalendarApp.EventColor.YELLOW);
console.log(newEvent.getId())
let changes = {
transparency: "transparent"
};
Calendar.Events.patch(changes, calendarId, newEvent.getId().replace("@google.com", ""));
}