"Object does not allow" 尝试通过高级日历服务更新事件的颜色时出错
"Object does not allow" error when trying to update an event's color via advanced Calendar service
基于@Ilya 的 answer,我创建了以下代码:
var event = CalendarApp.getCalendarById(calendarid).createEvent(
eventtitle,
startfull,
endfull,
{description: eventdescription,
location: eventaddress}
);
event.id = event.getId();
event.colorId = "#616161";
Calendar.Events.patch(event, calendarid, event.id);
主要是尝试将一些不太重要的事件“灰化”,同时将其他事件保留为默认日历颜色。这种颜色变化发生在与实际事件创建相同的执行过程中。该事件创建良好,但仅使用默认日历颜色。当上面的代码运行时,我得到一个错误:
Object does not allow properties to be added or changed.
我觉得可能跟this有关系,但不知道怎么解决。
为了其他用户将来参考,here's the best list 我现在能找到的颜色。
颜色ID可以通过Colors:get in CalendarAPI的方法获取。例如,您可以在 "Try this API" 测试此方法。在“变灰”的情况下,我认为颜色 ID 可能是 8
。所以请测试以下修改。
发件人:
var event = CalendarApp.getCalendarById(calendarid).createEvent(
eventtitle,
startfull,
endfull,
{description: eventdescription,
location: eventaddress}
);
event.id = event.getId();
event.colorId = "#616161";
Calendar.Events.patch(event, calendarid, event.id);
收件人:
var event = CalendarApp.getCalendarById(calendarid).createEvent(
eventtitle,
startfull,
endfull,
{description: eventdescription,
location: eventaddress}
);
Calendar.Events.patch({colorId: 8}, calendarid, event.getId().replace("@google.com", ""));
注:
- 很遗憾,
event.getId()
不能用于 Calendar.Events.patch
。在这种情况下,需要删除 @google.com
。请注意这一点。
- 如果要使用其他颜色,请检索颜色ID并使用。
参考文献:
基于@Ilya 的 answer,我创建了以下代码:
var event = CalendarApp.getCalendarById(calendarid).createEvent(
eventtitle,
startfull,
endfull,
{description: eventdescription,
location: eventaddress}
);
event.id = event.getId();
event.colorId = "#616161";
Calendar.Events.patch(event, calendarid, event.id);
主要是尝试将一些不太重要的事件“灰化”,同时将其他事件保留为默认日历颜色。这种颜色变化发生在与实际事件创建相同的执行过程中。该事件创建良好,但仅使用默认日历颜色。当上面的代码运行时,我得到一个错误:
Object does not allow properties to be added or changed.
我觉得可能跟this有关系,但不知道怎么解决。
为了其他用户将来参考,here's the best list 我现在能找到的颜色。
颜色ID可以通过Colors:get in CalendarAPI的方法获取。例如,您可以在 "Try this API" 测试此方法。在“变灰”的情况下,我认为颜色 ID 可能是 8
。所以请测试以下修改。
发件人:
var event = CalendarApp.getCalendarById(calendarid).createEvent(
eventtitle,
startfull,
endfull,
{description: eventdescription,
location: eventaddress}
);
event.id = event.getId();
event.colorId = "#616161";
Calendar.Events.patch(event, calendarid, event.id);
收件人:
var event = CalendarApp.getCalendarById(calendarid).createEvent(
eventtitle,
startfull,
endfull,
{description: eventdescription,
location: eventaddress}
);
Calendar.Events.patch({colorId: 8}, calendarid, event.getId().replace("@google.com", ""));
注:
- 很遗憾,
event.getId()
不能用于Calendar.Events.patch
。在这种情况下,需要删除@google.com
。请注意这一点。 - 如果要使用其他颜色,请检索颜色ID并使用。