我正在尝试使用Python Google Calendar API将参与者添加到插入的事件中。知道我哪里错了吗?我已经尝试并阅读了我能找到的所有内容。感谢。
brew_cal_body = {'attendees':{'email':'*********@gmail.com'},'end':{'date':'2014-08-20'},'start': {'date':'2014-08-18'},'summary':'TESTING THINGS'}
new_event = google_calendar.service.events().insert(calendarId=brew_cal_id, body=brew_cal_body,sendNotifications=True).execute()
new_event
{u'created': u'2014-08-15T19:41:46.000Z',
u'creator': {u'displayName': u'*********',
u'email': u'*************'},
u'end': {u'date': u'2014-08-20'},
u'etag': u'"2816263412782000"',
u'hangoutLink': u'******************',
u'htmlLink': u'********************',
u'iCalUID': u'********************',
u'id': u'v28jdhl0ikm9c2eb859f6rhj3k',
u'kind': u'calendar#event',
u'organizer': {u'displayName': u'Test Schedule',
u'email': u'*******************8',
u'self': True},
u'reminders': {u'useDefault': True},
u'sequence': 0,
u'start': {u'date': u'2014-08-18'},
u'status': u'confirmed',
u'summary': u'TESTING THINGS',
u'updated': u'2014-08-15T19:41:46.391Z'}
答案 0 :(得分:2)
与会者应该是一个词典列表,例如:
{'attendees':{'email':'*********@gmail.com'}
应该是:
{'attendees':[{'email':'*********@gmail.com'}]
我没有注意到文档中的括号,前者没有引发错误。希望这可以帮助别人拔掉头发。
答案 1 :(得分:0)
您应该使用API的更新功能来添加与会者,这是documentation。
答案 2 :(得分:0)
您可以尝试
def update_event_employee_email(service, calendarId, eventId, employee_email,displayName):
# First retrieve the event from the API.
event = service.events().get(calendarId=calendarId, eventId=eventId).execute()
#print(event)
add_attendees = {
"displayName": str(displayName),
"email": str(employee_email)
}
if event['attendees']:
attendees = event['attendees']
attendees.append(add_attendees)
body = {
"attendees": attendees
}
print(attendees)
else:
body = {
"attendees": [
{
"displayName": str(displayName),
"email": str(employee_email)
}
]
}
#print(event)
try:
event = service.events().patch(calendarId=calendarId, eventId=eventId, body=body).execute()
print(event['updated'])
except Exception as e:
print(json.loads(e.content)['error']['code'])
return print('Finist update attendees')