Google 日历事件不使用服务器中已设置的 colorId

问题描述 投票:0回答:1

我们的系统实际上通过在谷歌日历中创建事件来与谷歌日历集成。创建事件时,我们还让用户根据自己的喜好设置颜色。从技术上讲,我们在调用 Create Event API

时传递 colorId

但是,当我们在 Google 日历 GUI(网络和移动应用程序)上打开创建的事件时,它不会使用之前设置的 colorId。看起来他们的 GUI 使用在客户端中设置的颜色see image

有没有办法让 Google 日历 GUI(网络和移动应用程序)使用基于服务器中设置的 colorId 的颜色?

我已通过调用其 Get Event API

确保在服务器中正确设置了 colorId

期望:在 GUI 中,根据服务器中的 colorId 使用颜色

google-calendar-api
1个回答
0
投票

要根据服务器上设置的

colorId
使用颜色,您可以使用 Google Calendar API 中的
insert
方法。您可以通过访问 Google Developers 文章中的“插入”方法并使用右侧窗格中的 API Explorer 来测试这一点。

这是此请求的实际示例:

{
  "start": {
    "dateTime": "2024-07-10T18:30:00+03:00",
    "timeZone": "Europe/Bratislava"
  },
  "end": {
    "dateTime": "2024-07-10T19:30:00+03:00",
    "timeZone": "Europe/Bratislava"
  },
  "summary": "EventTitle",
  "colorId": "5"
}

首先,您可以使用用户的电子邮件地址作为

calendarId
。或者,您可以使用
CalendarList.list
方法检索用户列表中日历的 ID。如果用户有多个日历并且您需要确定要使用哪一个,这会很有帮助。

接下来,您可以使用

start
end
属性定义事件的时间范围。这些属性中的每一个都应该具有:

  • dateTime
    :ISO 8601 格式的事件开始和结束时间。

  • timeZone
    :活动时间的时区。

您还可以使用我在上面代码中突出显示的

summary
属性来设置事件的标题。最后,为了设置事件颜色,可以使用
colorId
property 来指定事件的颜色。
colorId
对应于服务器上预定义的一组颜色。

这是一组基于 colors.get 的响应的预定义

颜色

"event": {
  "1": {
   "background": "#a4bdfc",
   "foreground": "#1d1d1d"
  },
  "2": {
   "background": "#7ae7bf",
   "foreground": "#1d1d1d"
  },
  "3": {
   "background": "#dbadff",
   "foreground": "#1d1d1d"
  },
  "4": {
   "background": "#ff887c",
   "foreground": "#1d1d1d"
  },
  "5": {
   "background": "#fbd75b",
   "foreground": "#1d1d1d"
  },
  "6": {
   "background": "#ffb878",
   "foreground": "#1d1d1d"
  },
  "7": {
   "background": "#46d6db",
   "foreground": "#1d1d1d"
  },
  "8": {
   "background": "#e1e1e1",
   "foreground": "#1d1d1d"
  },
  "9": {
   "background": "#5484ed",
   "foreground": "#1d1d1d"
  },
  "10": {
   "background": "#51b749",
   "foreground": "#1d1d1d"
  },
  "11": {
   "background": "#dc2127",
   "foreground": "#1d1d1d"
  }
 }
© www.soinside.com 2019 - 2024. All rights reserved.