joc*_*ter 3 google-calendar-api google-apps-script
我想为事件设置特定的颜色.
我相信我必须使用Calendar API.我无法弄清楚如何做到这一点.
我正在尝试的代码是:
var event = CalendarApp.getOwnedCalendarById(calendarID).createEvent(class, startTime, endTime, {description:lessonPlanDataComplete[t], colorId: 11});
Run Code Online (Sandbox Code Playgroud)
在colorId11应该设置为红色,但所有事件出来作为默认颜色.
任何帮助/提示感激不尽,
非常感谢,西蒙
实际上可以使用高级日历服务.
(这篇文章很有帮助)
创建新活动的代码如下:(受Google的例子启发)
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());
}
Run Code Online (Sandbox Code Playgroud)
并修改现有事件(具有其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)
}
Run Code Online (Sandbox Code Playgroud)
使用(例如)Google在线API试用版列出颜色代码
在使用脚本编辑器中的ressources菜单运行此代码之前,必须启用高级Google日历服务,请参见下图.
小智 5
这总是可能的。而是尝试一下。
在你的函数中:
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');
Run Code Online (Sandbox Code Playgroud)
参考: https: //developers.google.com/apps-script/reference/calendar/event-color
要设置的字符串是事件颜色的数字字符串表示形式。
小智 0
目前这是不可能的。您可以在日历上使用 setColor,但不能在事件上使用。您可以从开发者页面发送有关该 API 的反馈,并希望它被添加。
同时,我建议您创建一个具有所需颜色的日历并将所有事件放入其中,因为这将使它们具有该颜色。
| 归档时间: |
|
| 查看次数: |
5423 次 |
| 最近记录: |