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


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

我使用谷歌日历API与PHP。我知道如何创建新日历,但是如何设置已创建的日历的颜色呢?我找了好几个小时了。我试过了

$calendar -> setColor();

我试过了

$calendar -> setColorId();

都是未定义的方法。我找到了关于如何修改颜色定义的文档。并使用

发送事件的颜色
$event -> setColorId();

但是我找不到任何关于如何设置日历颜色的内容

我认为你可以通过使用CalendarList: update来改变日历的颜色。

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

另外,Calendar API现在包含用于自定义日历颜色的字段。CalendarList资源现在包括取代colorIdbackgroundColorforegroundColor属性。要使用新的自定义颜色,在执行更新时将colorRgbFormat设置为True

来源:v3的新功能-日历的自定义颜色

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

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

其中$calendarListEntrycalendarList对象,您可以使用get方法获取。

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