Skip to content

Instantly share code, notes, and snippets.



Created Dec 7, 2012
What would you like to do?
use the calendar google-api from python as a service
Go to and:
- create a new project,
- enable access to the calendar api,
- create a "service account" - that will give you an:
* "email address" which is the service_account_name and
* a private key that you need to save on you server
- go to the calendar and share it with the "email address" from above
Make sure your time is synchronized.
requirements are: google-api-python-client and pyOpenSSL
pip install google-api-python-client pyOpenSSL
import pprint
import pytz
from datetime import datetime, timedelta
import httplib2
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
with open('privatekey.p12', 'rb') as f:
key =
service_account_name = ''
calendarId = ''
credentials = SignedJwtAssertionCredentials(
service_account_name, key,
http = httplib2.Http()
http = credentials.authorize(http)
service = build(serviceName='calendar', version='v3', http=http)
lists = service.calendarList().list().execute()
# get events from calendar for the next 3 days
cest = pytz.timezone('Europe/Skopje')
now = # timezone?
timeMin = datetime(year=now.year, month=now.month,, tzinfo=cest) + timedelta(days=1)
timeMin = timeMin.isoformat()
timeMax = datetime(year=now.year, month=now.month,, tzinfo=cest) + timedelta(days=3)
timeMax = timeMax.isoformat()
events =,
timeMin=timeMin, timeMax=timeMax).execute()

This comment has been minimized.

Copy link

@harish2sista harish2sista commented Feb 9, 2017

hello gdamjan
are you still able to execute this code with the new version of calendar API. If yes, can you please help me understand some of the terms you used here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment