gpt4 book ai didi

python - Google Calendar API 如何查找与会者列表

转载 作者:行者123 更新时间:2023-12-01 02:04:09 29 4
gpt4 key购买 nike

我需要使用 Google Calendar API 查找 session 的与会者列表。要提取与会者电子邮件,我有以下代码:

eventsResult = service.events().list(calendarId='primary',timeMin=tmin,timeMax=tmax,singleEvents=True,orderBy='startTime').execute()
events = eventsResult.get('items', [])

for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
end = event['end'].get('dateTime', event['end'].get('date'))
attendees = event['attendees'].get('email', event['attendees'].get('email'))
print(attendees)

但是出现错误

attendees = event['attendees'].get('email', event['attendees'].get('email'))
AttributeError: 'list' object has no attribute 'get'

我错过了什么?关于如何做到这一点有什么建议吗?

最佳答案

如果您正在寻找解决方案,那么这个怎么样? attendees的结构如下。

{
"items": [
{
"attendees": [
{
"email": "### email ###",
"displayName": "### name ###",
"responseStatus": "#####"
}
]
}
]
}

那么这个修改怎么样?

来自:

for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
end = event['end'].get('dateTime', event['end'].get('date'))
attendees = event['attendees'].get('email', event['attendees'].get('email'))
print(attendees)

致:

for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
end = event['end'].get('dateTime', event['end'].get('date'))
print("{0}, {1}".format(start, end))
for attendee in event['attendees']:
attendees = attendee.get('email', attendee.get('email'))
print(attendees)

如果我误解了您的问题并且您已经有了解决方案,我很抱歉。

关于python - Google Calendar API 如何查找与会者列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49231442/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com