Google Apps脚本:使用Calendar API设置事件的颜色 [英] Google Apps Script: Setting color of an event using Calendar API

查看:126
本文介绍了Google Apps脚本:使用Calendar API设置事件的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to set specific colors for events.

我认为我必须使用Calendar API.我不知道该怎么做.

I believe I have to use the Calendar API. I cannot figure out how to do this.

我正在尝试的代码是:

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

colorId 11应该设置为 red ,但是所有事件都会作为默认颜色显示.

The colorId 11 should set as red, but all events coming out as default color.

任何帮助/提示,​​感激不尽,

Any helps/hints gratefully received,

非常感谢,西蒙

推荐答案

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

It is actually possible using the advanced Calendar Service.

( ="这篇文章很有帮助)

创建新事件的代码如下:(灵感来自 Google的示例)

The code to create a new event goes like this : (inspired by 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)是这样的:

and to modify an existing event (having its ID) goes like that :

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列出颜色代码在线API试用在这里

必须先启用高级Google日历服务,然后才能使用脚本编辑器中的资源"菜单运行此代码,请参见下图.

The advanced Google Calendar Service has to be enabled before you run this code using the ressources menu in the script editor, see illustration below.

这篇关于Google Apps脚本:使用Calendar API设置事件的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆