在Google日历中更改事件的颜色

时间:2016-02-18 12:55:54

标签: javascript google-apps-script google-calendar-api

我尝试使用Google Apps脚本中的高级日历服务来更改日历中特定事件的colorId。

到目前为止,我已经能够列出获取事件以及我喜欢的事件。所以我有活动的ID。

function getSpecificEvent(){
  var calendarId = 'primary';
  var eventId = '7h2tbvns2oo4r5gku6ghjfjclk';
  var calEvent = Calendar.Events.get(calendarId, eventId);
  Logger.log(calEvent);
}

这是我在编辑colorID时尝试的,我使用 patch

function setEventColor(){
  var calendarId = 'primary';
  var eventId = '7h2tbvns2oo4r5gku6ghjfjclk';
   Calendar.Events.patch(calendarId, eventId).colorId('11');
}

但后来我得到了这个错误: enter image description here

在这种情况下,第33行是这一行:

   Calendar.Events.patch(calendarId, eventId).colorId

1 个答案:

答案 0 :(得分:5)

这有点棘手......但我发现它是如何工作的:

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)
}

This post(匿名)非常有帮助

相关问题