Git Product home page Git Product logo

zigbee-s / flask-calendar-event-api Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 4.0 131 KB

This project demonstrates how to build a Python Flask API that connects to Google Calendar API. Users can connect their Google calendar with this service, store user tokens in the database, and retrieve calendar events for a specific date range using those tokens.

Shell 0.28% Python 92.98% HTML 3.90% Dockerfile 2.84%
docker flask googlecalendarapi googleoauth2 mongodb python

flask-calendar-event-api's Introduction

Google Calendar API Integration with Python Flask

This project demonstrates how to build a Python Flask API that connects to Google Calendar API. Users can connect their Google calendar with this service, store user tokens in the database, and retrieve calendar events for a specific date range using those tokens.

Installation

MongoDB Setup

Before running the application, you need to have a MongoDB instance running. You can create a free instance on MongoDB Atlas.

Schema

# Define MongoDB schema
user_schema = {
    'user_id': str,
    'credentials_data': dict,
    'credentials': str
}

Google Cloud Console Setup

  1. Create a project on the Google Cloud Console.
  2. Create OAuth2 credentials for the project by following the steps and Enable the Google Calendar API for the project.

First setup a OAuth Screen

  • Keep user type external
  • You can keep the app domain, and the Authorized domain sections empty
  • Click on ADD or remove scopes: and select:
    https://www.googleapis.com/auth/calendar
    
  • In Test Users add your email id

Setup credentials

  • create new credentials
  • Select OAuth client ID
  • In Applicatio type select web application
  • Under Authorized JavaScript origins add:
http://localhost:5000
  • Under Authorized redirect URIs add:
http://localhost:5000/callback
  1. Download the client_secret.json file

Setup Using Docker

  1. Clone this repository using git clone https://github.com//google-calendar-api.git
  2. Navigate to the cloned repository
  3. Build a docker image using
docker build -t meet:1.0.0 .
  1. Run the docker image using the following command:
docker run -p 5000:5000 \
-e MONGO_URI=<your-mongodb-connection-string> \
-e MONGO_DB=<your-mongodb-database> \
-e MONGO_COLLECTION=<your-mongodb-collection> \
-e GOOGLE_CLIENT_ID=<your-google-client-id> \
-e CLIENT_SECRET=<your-google-client-secret> \
meet:1.0.0

Note: Here MongoDB uri should be url encoded, and if there's a & symbol, it should come in "", also the CLIENT_SECRET recieves the json data of your client_secret.jsom file, wrapped in single inverted commas ''.

  1. Access the application by visiting http://localhost:5000 on your web browser.

Setup on Local Device

  1. Clone this repository using git clone https://github.com//google-calendar-api.git
  2. Navigate to the cloned repository using cd google-calendar-api
  3. Create a Python virtual environment using python -m venv env
  4. Activate the environment using source env/bin/activate (Linux/Mac) or env\Scripts\activate (Windows)
  5. Install the dependencies using pip install -r requirements.txt
  6. Create a .env file in the app directory with the following environment variables:
GOOGLE_CLIENT_SECRET=<your-google-client-secret>
GOOGLE_CLIENT_ID=<your-google-client-id>
MONGO_URI=<your-mongodb-connection-string>
MONGO_DB=<your-mongodb-database>
MONGO_COLLECTION=<your-mongodb-collection>
CLIENT_SECRET=<your-google-client-secret-json>

Note: Here MongoDB uri should be url encoded, and if there's a & symbol, it should come in "", also the CLIENT_SECRET recieves the json data of your client_secret.jsom file, wrapped in single inverted commas ''.

  1. Start the application using
flask run
  1. Access the application by visiting http://localhost:5000 on your web browser.

Usage

Routes

/: Home page /login: Login using Google OAuth2 /logout: Clears the session /events (GET): Page to select the dates /events (POST): Pass in start_date, end_date, and user_id (Your Google ID)

Features

  • Uses Flask-Limiter to limit the number of requests. The /events route is limited to 5 requests per minute for testing purposes.
  • Uses refresh_token to automatically refresh the tokens. If the refresh_token is expired, the user is redirected to the sign-in page.

Usage screenshots

  1. Index page

Index Page

  1. OAuth page

OAuth page

  1. Events range page

Events range page

  1. Events result page | Post request

Events result page

  1. Limit handling

limit handling

  1. Postman post request

Postman post request

  1. Docker hosted

Docker Hosted

flask-calendar-event-api's People

Contributors

zigbee-s avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

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.