Google Calendar API with Python Demo

By Dr. Louay Chebib

 

 

https://github.com/Netuser-Py/calendar_Demo

Google Calendar API

"Google Calendar is a time-management and scheduling calendar service developed by Google."

 

Widely used and is available for web, Android and iOS.

Strongly integrated into the Google Environment.

Supports reminders, shared events, & shared calendars.

Google Calendar (calendar.google.com)

Google Calendar API

  • Requires Google API Credentials and Token
    • get credentials: (Turn on the Google Calendar API)
    •                                    click the Enable the Google Calendar API button
    • click DOWNLOAD CLIENT CONFIGURATION and save as credentials.json to your working directory.
  • pip install google-api-python-client

    • pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib

Setup

Google Calendar API

Demo: quickstart.py (Google Demo)

  • Run quickstart.py to create a Token and get next ten events from the Calendar. Use appropriate AUTH
  • Reply to the prompts until you see "The authentication flow has completed. You may close this window."

Google Calendar API

API Objects

Review Calendar Application Concepts: calendars, events, attendees...

  • Event — An event on a calendar containing information such as the title, start and end times, and attendees.
  • Calendar — A calendar is a collection of events.
  • Calendar List — A list of all calendars on a user's calendar.
  • Setting — A user preference.
  • ACL — An access control rule.
  • Color — A color presented in the Calendar UI.
  • Free/busy — A time when a calendar has events scheduled is considered "busy".

 

 

Google Calendar API

Decoding & Dates

Coordinated Universal Time (UTC) is everything!

  • UTC is the "secret sauce" that makes it all happen.
  • Mountain Standard Time (MST) is UTC-7
  • Mountain Daylight Time (MDT) UTC-6
  • Best practice is to convert to UTC before talking to the API
  • Use Python: pytz & datetime
    • from pytz import timezone
    • from datetime import datetime, timedelta
  • see demo in UTC_stuff.py
  • "maya" parser str: yyyy-mm-ddThh:mm:ss.ssssssZ to datetime

Google Calendar API 

List Calendars

Calendar has multiple Calendars!

  • Calendar List: Make a list of calendars: list_cals()
  • Call the API with default: calendarId='primary'

  • Use the calendarId= from calendar properties in the APP

  • Event(s):

    • get next 10 events

    • set a start datetime using: timeMin=

    • list of events

    • look at  fields in the event object

    • Watch for: events that end outside/span your time range...

  • insert event

Google Calendar API with Python

By Dr. L. Chebib

Google Calendar API with Python

Using Python Google Calendar API

  • 1,265