How to use Python to create a google calendar event via API v3

The following official page gives an example on how to create an event with Python. https://developers.google.com/google-apps/calendar/v3/reference/events/insert#examples

The code they gave is listed below:

event = {
  'summary': 'Appointment',
  'location': 'Somewhere',
  'start': {
    'dateTime': '2011-06-03T10:00:00.000-07:00'
  },
  'end': {
   'dateTime': '2011-06-03T10:25:00.000-07:00'
  },
  'attendees': [
  {
    'email': 'attendeeEmail',
    # Other attendee data...
  },
  # ...
  ],
}

created_event = service.events().insert(calendarId='primary', body=event).execute()

print created_event['id']

      

However, the example above does not indicate how to establish a connection and create a variable service

. Since I have set my calendar to be public I think it would be very easy to create service

.

Does anyone know how to establish a connection?

+3


source to share


1 answer


I had a hard time figuring out how to use the Google Calendar api with OAuth, etc. I finally got everything working and wrote a simple, easy-to-use package along the way. I've uploaded it to github and can be installed from pypi using "pip install gback". The documentation also contains instructions for google account settings.

https://github.com/Schwarzschild/gback

Here is a snippit example for adding an appointment to a calendar.



from gback import GCalSession

# print the output will display the appiointment url.
# 'Marc' is the name of the calendar used.

session = GCalSession('~/gback.oauth')
des='Write a simpler way to use the google calendar api.'
print session['Marc'].add('Write Python code.', '20150430', des=des)

      

Enjoy Mark

+2


source







All Articles