URL). However, the Google Data’s..." /> URL). However, the Google Data’s..." />

Using Python Google Data APIs to create public google calendar

2 min 6 sec read
In Code

Recently, I have a chance to use the Python Google Data library, my task is creating a public Google Calendar (the calendar that everyone can see every details with a given URL). However, the Google Data’s documentation for Python is quite basic and does not mention what I need. It took me a while to trying to search the ACL and study.

Now, I am not sure this is the best way to do it, yet at least, it is a workable solution.

import gdata
from gdata import calendar
from gdata.calendar import client
from gdata import atom
from gdata.calendar import service

#create the calendar
calendar_client = gdata.calendar.client.CalendarClient(source='quang.be')
calendar_client.ssl = True
calendar_client.ClientLogin('my gmail adresss', 'my Password')
calendar_entry = gdata.calendar.data.CalendarEntry()
calendar_entry.title = atom.data.Title(text="My calendar title")
calendar_entry.summary = atom.data.Summary(text='describe my calendar') calendar_entry.where.append(gdata.calendar.data.CalendarWhere(value='Vietnam'))
calendar_entry.color = gdata.calendar.data.ColorProperty(value='#2952A3')
calendar_entry.timezone = gdata.calendar.data.TimeZoneProperty(value='Asia/Saigon') calendar_entry.hidden = gdata.calendar.data.HiddenProperty(value='false')
new_calendar = calendar_client.InsertCalendar(new_calendar=calendar_entry)

#update the acl for my calendar
calendar_id = str(new_calendar.get_id()).split("/")[7]
acl_entry = gdata.calendar.CalendarAclEntry()
acl_entry.scope = gdata.calendar.Scope(scope_type="default")
roleValue = 'http://schemas.google.com/gCal/2005#%s' % ('read') #everyone can see my calendar details
acl_entry.role = gdata.calendar.Role(value=roleValue)
insert_uri = "https://www.google.com/calendar/feeds/"+ calendar_id +"/acl/full"
service = gdata.calendar.service.CalendarService()
service.ClientLogin('my gmail address', 'my password', source="quang.be")
service.InsertAclEntry(acl_entry, insert_uri)