Changing Color on Event in Google Calendar

2020-04-12 09:40发布

Im trying to use the advanced calendar service in Google Apps Script to change the colorId on a particular event in my calendar.

So far i have been able to list and get event's and the event i like. So i have the ID of the event.

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

This is what im trying when editing the colorID, i use patch:

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

But then i get this error: enter image description here

Line 33 in this case is this line:

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

1条回答
叛逆
2楼-- · 2020-04-12 10:16

This is a bit tricky... but I found how it works :

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 (anonymous) was very helpful

查看更多
登录 后发表回答