Django Google Calendar Integration


1. Init

Refer Google OAuth Documentation

  1. Creates an instance of google_auth_oauthlib.flow.Flow by reading the client secrets from a specified file.
  2. Sets the redirect URI to a specified URL, which must match one of the authorized redirect URIs for the OAuth 2.0 client.
  3. Generates an authorization URL and a state, which is used to initiate the OAuth 2.0 authorization grant flow.
  4. Stores the state in the session so that it can be verified in the authorization server response.
  5. Returns a Response object with the authorization URL as its content.

2. Redirect

  1. Starts by retrieving the state from the session and creating an OAuth2 flow object with the specified client secrets file and scopes.
  2. Exchanges the authorization code in the authorization server's response for OAuth 2.0 tokens using the "fetch_token" method of the flow object.
  3. Resulting credentials object is saved to the session in a dictionary form.
  4. Saved credentials are then loaded from the session and used to build a client library for the Google Calendar API.
  5. Fetches the calendar list for the user and retrieves the first calendar in the list

Problems likely to face

  1. KeyError: 'client_secret'

  2. Enable the Calendar API in Cloud Console


The CalDAV API lets you manage your Google calendars and events.

Resources List