【问题标题】:Adding attendees with Google Calendar API使用 Google Calendar API 添加与会者
【发布时间】:2014-10-09 14:09:44
【问题描述】:

我正在尝试使用 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'}

【问题讨论】:

    标签: python api calendar google-api google-api-python-client


    【解决方案1】:

    参与者应该是一个字典列表,例如:

    {'attendees':{'email':'*********@gmail.com'}
    

    应该是:

    {'attendees':[{'email':'*********@gmail.com'}]
    

    我没有注意到文档中的括号,并且前者没有引发错误。希望这可以帮助某人拔掉头发。

    【讨论】:

      【解决方案2】:

      你可以试试

      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')
      

      【讨论】:

        【解决方案3】:

        您应该使用 API 的更新功能来添加与会者,这里是 documentation

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-05-22
          相关资源
          最近更新 更多