Changing Color on Event in Google Calendar

2020-04-12 10:21发布

问题:

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:

Line 33 in this case is this line:

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

回答1:

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