我想为事件设置特定的颜色。
我相信我必须使用Calendar API。我无法弄清楚如何做到这一点。
我正在尝试的代码是:
var event = CalendarApp.getOwnedCalendarById(calendarID).createEvent(class, startTime, endTime, {description:lessonPlanDataComplete[t], colorId: 11});
colorId
11应设为红色,但所有事件均为默认颜色。
感激地收到任何帮助/提示,
非常感谢,西蒙
答案 0 :(得分:5)
实际上可以使用高级日历服务。
创建新活动的代码如下:(受Google's example启发)
function createEvent() {
var calendarId = 'primary';
var event = {
summary: 'Other test',
location: 'right here',
description:' chat... ;-)',
start: {
dateTime: new Date().toISOString()
},
end: {
dateTime: new Date(new Date().getTime()+3600000).toISOString()
},
attendees: [
{email: 'user@gmail.com'}
],
// Red background. Use Calendar.Colors.get() for the full list.
colorId: 11
};
event = Calendar.Events.insert(event, calendarId);
Logger.log('Event ID: ' + event.getId());
}
并修改现有事件(具有其ID)如下:
function ChangeEventColor(){
var calendarId = 'primary';
var eventId = 'omv°°°°°°°°°°8jbs'
var event = Calendar.Events.get(calendarId, eventId)
Logger.log('current color = '+event.colorId)
event.colorId = 11
Calendar.Events.patch(event,calendarId,eventId);
Logger.log('new color = '+event.colorId)
}
使用(例如)Google online API tryout here
列出颜色代码在使用脚本编辑器中的ressources菜单运行此代码之前,必须先启用高级Google日历服务,请参阅下图。
答案 1 :(得分:2)
这总是可行的。试试吧。
在您的函数中:
var newEvent = calendar.createEvent(event_title, event_start_time, event_end_time,
{
location: event_location,
guests: newGuests,
sendInvites: 'true',
description: event_description
}
);
newEvent.setColor('4');
请参阅:https://developers.google.com/apps-script/reference/calendar/event-color
要设置的字符串是事件颜色的数字字符串表示形式。
答案 2 :(得分:1)
目前无法做到这一点。您可以在日历上使用setColor,但不能在事件上使用。您可以从开发者页面发送有关API的反馈,并希望它被添加。
与此同时,我建议您创建一个具有所需颜色的日历,并将所有事件放在那里,因为这将使它们具有该颜色。