Code Monkey home page Code Monkey logo

django-google-calendar's Introduction

Django-Google Calendar Integration

This project lays out how to integrate google Calendar with your Django application using Service accounts. It should give you enough to integrate your application without problems. For more information please look it up using google or email me.

Why Service Accounts?

Service accounts allow you to integrate your application without needing permissions from each user and without having to make them log into their Google account.

Start

  1. Run the following command to initialize the Django Project
pip install django google-api-python-client oauth2client gunicorn whitenoise 
or 
pipenv install 
or
pip install requirements.txt

Set the values in the .env file

calendarId=...
UPDATE_GOOGLE=True
client_secret=...

The Google Part

  1. Go to the Google Cloud Platform and make and account/log in.
  2. Create a new Google Cloud and call it whatever you want. Im calling mine Test Google Events
  3. On the top left of the screen next to the Google Cloud logo, click and select your project.

Creating a Sercive account

  1. On the home page of your project click the APIs and Services Option
  2. Go to the Credentials tab (on the left menu)
  3. Select 'Manage service accounts' (for me it was just above the Service Account table on the right)
  4. Select Create Service Account on the top
    1. fill in everything normally
    2. Give it the role of owner (You can give it a more defined role if you wish but it is up to you to research which role you want for that service account)
    3. Administrators are optional
    4. Once you save you will be take back to the service account page
    5. Save the service account email that is genereated
  5. Under Actions click the menu of the service account you want to use and select 'Manage Keys'
  6. Select 'Add Key'
    1. Select JSON and press 'Create'(this will download a key file to your computer)
  7. Open this file and put it all into one line (so that we can add it to the environment variables)
  8. Add it to the environment variables under the name client_secret
  9. (for this to work you need to make sure that the key can be read by json.load(os.environ.get('client_secret')) otherwise it will not work correctly)

Giving API access

  1. Click on the menu on the top left and select APIs & Services
  2. In the 'Enabled APIs & services' screen, press 'Enable APIS and Services'
  3. Find and enable the 'Google Calendar API'

Link Google Calendar

  1. Go to Google Calendar
  2. (Make a new Google Calendar if you dont have one already)
  3. On into the Settings of the Calendar
  4. Go to Share with specific people or groups
    1. Share with the service account
    2. 'Give make changes to events' Permisson
  5. Scroll down to Integrate Calendar
  6. Copy "Calendar ID" and add it as an environment variable called "calendarId"

Your Django project and Google Calendar are now linked

Back to the Project

  1. launch the project
gunicorn google_events.wsgi --log-file - 
or 
python manage.py runserver
  1. Create an Event this should now show up on the Google Calendar you linked

Thats is it!

Final Notes

When you open the admin interface you will see that there is a Google events page. This page shows all the events that are in the google calendar it and whether they are linked to an event in your Database.

If you set UPDATE_GOOGLE environment variable to False, 0 events will not be sent to google.

adding to this repo

If you feel like there is a better way of doing something, please create a merge request and i will have a look at it and merge it if it is good.

hope this has been helpful

More information on the Calendar API can be found in the Google's Quickstart Guide

django-google-calendar's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.