首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Google日历API无法获取事件colorid - Python

Google日历API无法获取事件colorid - Python
EN

Stack Overflow用户
提问于 2018-07-25 21:46:19
回答 1查看 342关注 0票数 1

我在使用谷歌日历API时遇到了这个问题,我试图让它找出事件的颜色,但由于某种奇怪的原因,它不起作用。我试图找到一个解决方案,但到目前为止还是没有希望。

代码语言:javascript
运行
复制
 def greet(self):
    self.pikk=(self.variable.get())
    print(self.pikk)
    self.ckbx = self.ivar.get()
    print(self.ckbx)
    self.SCOPES = "https://www.googleapis.com/auth/calendar"
    self.store = file.Storage('credentials.json')
    self.creds = self.store.get()
    if not self.creds or self.creds.invalid:
        self.flow = client.flow_from_clientsecrets('client_secret.json', self.SCOPES)
        self.creds = tools.run_flow(self.flow, self.store)
    self.service = build('calendar', 'v3', http=self.creds.authorize(Http()))

    self.now = datetime.datetime.utcnow().isoformat() + 'Z'
    self.events_result = self.service.events().list(calendarId='primary', timeMin=self.now,
                                          maxResults=10, singleEvents=True,
                                          orderBy='startTime').execute()
    self.events = self.events_result.get('items', [])

    self.lievent = []

    if not self.events:
        print('No upcoming events found.')
    for self.event in self.events:
        self.start = self.event['start'].get('dateTime', self.event['start'].get('date'))
        print(self.start, self.event['colorId'])
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-25 22:26:40

self.event['colorId']返回颜色的id。要获得相关的颜色值,必须调用colors().get()方法。

colors = service.colors().get().execute()

下面是如何在您的示例中使用它:

代码语言:javascript
运行
复制
.
.
.

self.events_result = self.service.events().list(calendarId='primary', timeMin=self.now,
                                          maxResults=10, singleEvents=True,
                                          orderBy='startTime').execute()


# Get the list of colors
colors = service.colors().get().execute()

.
.
.

# Then when you print, you can use it like,

print(self.start, colors['calendar'][event['colorId']]['background'])

https://developers.google.com/calendar/v3/reference/colors/get

希望它能有所帮助!!如果您有任何疑问,请随时询问:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51520526

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档