This repository contains code for integrating with Google Calendar API using OAuth 2.0 authentication. The code is implemented in Django and provides two endpoints for the integration.
This endpoint initiates the OAuth 2.0 flow for Google Calendar API. It prompts the user to provide their credentials.
- The user accesses this endpoint, triggering the initiation of the OAuth flow.
- The user will be redirected to the Google authentication page, where they will be prompted to log in and grant permission for the application to access their Google Calendar data.
- After successful authentication and authorization, the user will be redirected back to the
/rest/v1/calendar/redirect/
endpoint.
This endpoint handles the redirect request sent by Google after the user grants authorization. It performs two tasks:
- Handles the redirect request and retrieves the authorization code from Google.
- Uses the authorization code to obtain the access token for the user's Google Calendar.
- Google redirects the user to this endpoint with the authorization code.
- The endpoint retrieves the authorization code from the request parameters.
- Using the authorization code, the endpoint exchanges it for an access token by making a request to Google's token endpoint.
- Upon successful retrieval of the access token, the endpoint can make subsequent requests to the Google Calendar API on behalf of the user.
- The endpoint fetches the list of events from the user's calendar using the obtained access token.
To get started with this repository, follow these steps:
-
Clone the repository to your local machine:
git clone https://github.com/akashraj98/googleconnect.git
-
Install the required dependencies using pip:
-
pip install -r requirements.txt
-
Set up Google API credentials: Go to the Google Cloud Console. Create a new project (or select an existing one). Enable the Google Calendar API for the project. Create OAuth 2.0 credentials for the project. Download the credentials file (JSON format). Rename the downloaded file to credentials.json. Place the credentials.json file in the root directory of the repository.
5.Start the Django development server:
python manage.py runserver