使用Apps脚本将颜色更改为Google日历中的全天事件

时间:2016-10-13 07:48:43

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

我在谷歌日历中使用谷歌应用脚​​本更改全天活动的颜色时出现问题。 我测试了很多方法,但没有任何作用。

var event = CalendarApp.getCalendarById(calendrierId).createAllDayEvent(title,date).addPopupReminder(1440);

有没有人有解决方案

由于

1 个答案:

答案 0 :(得分:1)

您需要使用Advanced Calendar Service(必须是enabled before use。在脚本编辑器中选择资源>高级Google服务...然后在Google Developers Console中启用它。)

启用后,您可以使用 Events: insert创建活动,并使用 colorId 设置活动的颜色,这是一个示例:

function myFunction() {
  var calendarId = '{YOUR_CALENDAR_ID}';
  var date = "2016-12-25";
  var event = {
    summary: 'Christmas Day',
    location: 'Home',
    start: {
      date: date
    },
    end: {
      date: date
    },
    // Bold Red background.
    colorId: 11
  };
  Calendar.Events.insert(event, calendarId);
}

截至今天,有11种颜色可用于事件,您可以使用Calendar.Colors.get()作为完整列表,但这里有一个表格,其中包含您可能更熟悉的UI中使用的名称:

|    name    | colorId | background |
|------------|---------|------------|
| Blue       |    1    |   #a4bdfc  |
| Turquoise  |    2    |   #7ae7bf  |
| Purple     |    3    |   #dbadff  |
| Red        |    4    |   #ff887c  |
| Yellow     |    5    |   #fbd75b  |
| Orange     |    6    |   #ffb878  |
| Turquoise  |    7    |   #46d6db  |
| Gray       |    8    |   #e1e1e1  |
| Bold Blue  |    9    |   #5484ed  |
| Bold Green |    10   |   #51b749  |
| Bold Red   |    11   |   #dc2127  |