Search code examples
pythongoogle-calendar-apigdata-api

How to create/list events in calendars other than default using Google's API for Python?


Using the gdata API for Python, how do I create or list events in a calendar other than the default one?


Solution

  • You have to get the url of the custom calendar you want to read/write to, and supply it in the event query. This is what I came up with:

    #define cal_client:
    self.cal_client = gdata.calendar.client.CalendarClient(source='Milosz-GCal-1.0')
    #initiate calendar service (log in):
    self.cal_client.ClientLogin(email, password, self.cal_client.source);
    #get url for custom calendar (cal_index):
    self.cal_url=self.cal_client.GetOwnCalendarsFeed().entry[self.cal_index].GetAlternateLink().href
    #then, to read from the custom calendar:
    self.feed=self.cal_client.GetCalendarEventFeed(self.cal_url)
    #and to write to custom calendar:
    new_event = self.cal_client.InsertEvent(event,self.cal_url)