如何设置通过 API 创建的 Google 日历的颜色

How to set the color of a Google Calendar that was created via the API

我正在使用 google 日历 API 和 PHP。我知道如何创建新日历,但如何设置我创建的日历的颜色?我一直在寻找几个小时。我试过了

$calendar -> setColor();

我试过了

$calendar -> setColorId();

这两个都是未定义的方法。我找到了关于如何 modify the color definitions 的文档。并发送事件的颜色

$event -> setColorId();

但是我在任何地方都找不到关于如何设置日历颜色的任何信息。

我认为您可以使用 CalendarList: update 更改日历的颜色。

据称 here CalendarList 是用户添加到其列表中的所有日历条目的集合(显示在网络的左侧面板 UI 中)。您可以使用它来添加和删除现有日历 to/from 用户列表。您还可以使用它来检索和设置特定于用户的日历属性的值,例如默认提醒。另一个例子是 前景色,因为不同的用户可以为同一个日历设置不同的颜色。

此外,日历 API 现在包括自定义 colors for calendars. The CalendarList 资源的字段,现在包括取代 colorIdbackgroundColorforegroundColor 属性。要使用新的自定义颜色,请在执行更新时将 colorRgbFormat 设置为 True

来源:What's New in v3 - Custom colors for Calendars

根据@KENdi 接受的答案,我很难弄清楚语法。对于任何想要快速 PHP 解决方案的人:

$updatedCalendarListEntry = $service->calendarList->update($calendarListEntry->getId(), $calendarListEntry, array("colorRgbFormat" => true));

其中 $calendarListEntry 是您可以使用 get 方法获取的 calendarList 对象。

这允许使用 $calendarListEntry->setBackgroundColor("$calColor);,其中 $calColor 是包含六色代码的字符串,例如。 7e7e7e.