我在使用Google Calendar API时遇到了这个问题,我试图让它找出事件是什么颜色,但由于某种奇怪的原因,它无法正常工作。我试图找到一种解决方案,但到目前为止,它已经毫无希望。
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'])
答案 0 :(得分:0)
self.event['colorId']
返回颜色的ID。要获取相关的颜色值,必须调用colors().get()
方法。
colors = service.colors().get().execute()
在您的示例中如何使用它:
.
.
.
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
希望有帮助!!随时问您是否有任何疑问:)