pythoninsertgoogle-calendar-apievent-id

How can I custom my Event ID of Google Calendar when I input new event with Google Calendar API Python?


I want to insert Event ID that I want, to Google Calendar API with Python, but I don't know how to do it,

 event = {
      'summary': acara,
      'location': lokasi,
      'description': deskripsi,
      'start': {
        'dateTime': start_time.strftime("%Y-%m-%dT%H:%M:%S"),
        'timeZone': timezone,
      },
      'end': {
        'dateTime': end_time.strftime("%Y-%m-%dT%H:%M:%S"),
        'timeZone': timezone,
      },


      'attendees': attendees,

      'reminders': {
        'useDefault': False,
        'overrides': [
          {'method': 'email', 'minutes': 24 * 60},
          {'method': 'popup', 'minutes': 10},
        ],
      },
    }

Solution

  • You can specify your custom event Id by simply adding the field id to the event resource:

     event = {
          'id': 123456
          'summary': acara,
          'location': lokasi,
          'description': deskripsi,
          'start': {
            'dateTime': start_time.strftime("%Y-%m-%dT%H:%M:%S"),
            'timeZone': timezone,
          },
          'end': {
            'dateTime': end_time.strftime("%Y-%m-%dT%H:%M:%S"),
            'timeZone': timezone,
          },
    
    
          'attendees': attendees,
    
          'reminders': {
            'useDefault': False,
            'overrides': [
              {'method': 'email', 'minutes': 24 * 60},
              {'method': 'popup', 'minutes': 10},
            ],
          },
        }
    

    Important

    The event id needs to fulfill certain criteria as specified in the documentation:

    When creating new single or recurring events, you can specify their IDs. Provided IDs must follow these rules:

    characters allowed in the ID are those used in base32hex encoding, i.e. lowercase letters a-v and digits 0-9, see section 3.1.2 in RFC2938

    the length of the ID must be between 5 and 1024 characters

    the ID must be unique per calendar

    Due to the globally distributed nature of the system, we cannot guarantee that ID collisions will be detected at event creation time. To minimize the risk of collisions we recommend using an established UUID algorithm such as one described in RFC4122.

    If you do not specify an ID, it will be automatically generated by the server.

    Note that the icalUID and the id are not identical and only one of them should be supplied at event creation time. One difference in their semantics is that in recurring events, all occurrences of one event have different ids while they all share the same icalUIDs.)