google-apps-script - Google Apps 脚本 : Setting color of an event using Calendar API

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

我想为事件设置特定的颜色。

我相信我必须使用日历 API。我不知道该怎么做。

我正在尝试的代码是:

var event = CalendarApp.getOwnedCalendarById(calendarID).createEvent(class, startTime, endTime, {description:lessonPlanDataComplete[t], colorId: 11});

colorId 11 应设置为 red,但所有事件均以默认颜色显示。

感激地收到任何帮助/提示,​​

非常感谢,西蒙

最佳答案

实际上可以使用高级日历服务。

( This post was helpful )

创建新事件的代码如下所示:(受 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 列出颜色代码

在您使用脚本编辑器中的资源菜单运行此代码之前,必须启用高级 Google 日历服务,请参见下图。

enter image description here

关于google-apps-script - Google Apps 脚本 : Setting color of an event using Calendar API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31548227/

相关文章:

javascript - Google 应用程序脚本侧边栏因 onclick 而变成空白

javascript - 通过 Google Calendar API 发送事件的电子邮件通知

java - 有没有办法在 App Engine 上管理用户的日历约会?

android - 如何在 Android 应用程序中创建/使用日历(不作为 Intent)

python-3.x - 使用 python 和 Google Calendar API 创建一个带有 session 的事件创建事件而不是 session

google-apps-script - 为什么 copyTo(... PASTE_VALUES) 在宏中间不起作用?

google-apps-script - Google Apps 脚本 - 找不到函数

jdbc - Google Apps Script JDBC 连接问题

google-calendar-api - 生成 Google Hangouts session URL

javascript - 有条件地对范围进行排序