pythongoogle-calendar-apigoogle-meet

How to add conferenceDataVersion in Python?


I'm trying to create a Google Meet meeting using Google Calendar. After reading the documentation, I saw that there is a variable that is responsible for creating a meeting (conferenceDataVersion). I tried to declare it in different places, but it doesn't work. But simple events are created.

class GoogleCalendar:
    def add_event(self, calendar_id, body):
        return self.service.events().insert(
            calendarId = calendar_id, 
            body = body).execute()

obj = GoogleCalendar()
calendar = 'gmail@gmail.com'

event = {
  'conferenceDataVersion': 1,
  'summary': 'Тест',
  'location': 'Минск',
  'description': 'Описание',
  'start': {
    'date': '2023-05-25',
  },
  'end': {
    'date': '2023-05-26',
  },
  'conferenceData': {
      'createRequest': {
          'requestId': 'somestring',
          'conferenceSolutionKey': { 
              'type': 'hangoutsMeet' 
              },
      },
  }
}

event = obj.add_event(calendar_id = calendar, body = event)

I tried to declare conferenceDataVersion in add_event, but swore at the incorrect declaration of the variable.

version = 1
    def add_event(self, calendar_id, body, conference_data_version ):
        return self.service.events().insert(
            calendarId = calendar_id, 
            body = body, conferenceDataVersion = conference_data_version).execute()

event = obj.add_event(calendar_id = calendar, body = event, conference_data_version = version)

Solution

  • conferenceDataVersion is the argument of .insert method:

    service.events().insert(calendarId=calendar_id, body=body, conferenceDataVersion=1)
    

    I'd suggest using a google-calendar-simple-api (disclaimer: I might be biased because I'm the author of the library). Install it with:

    pip install gcsa
    

    Here is the equivalent code using google-calendar-simple-api:

    from datetime import date
    from gcsa.google_calendar import GoogleCalendar
    from gcsa.event import Event
    from gcsa.conference import ConferenceSolutionCreateRequest, SolutionType
    
    calendar = 'gmail@gmail.com'
    gc = GoogleCalendar(calendar)
    
    event = Event(
        'Тест',
        location='Минск',
        description='Описание',
        start=date(2023, 5, 25),
        conference_solution=ConferenceSolutionCreateRequest(
            solution_type=SolutionType.HANGOUTS_MEET,
        )
    )
    
    event = gc.add_event(event)
    

    Here is more info on conference solutions.