Data communication between Django and Google Calendar API

Google offers a variety of services with APIs that enable the creation of advanced web applications. all APIs offered by Google are easy to use and highly functional. Among them, Google Calendar API offers the best functionality as a calendar API.

Django, on the other hand, has one of the largest user base of any web framework, but there are surprisingly few tutorials on the Internet on how to use the google calendar API with Django.

In particular, in order to integrate Django with the google calendar API, it is necessary to use an API that connects the application to the application, rather than an API that connects the user to the application, but there are very few articles on this point.

When integrating google calendar API in Django, there are a some points that need to be noticed, such as the above. However, many beginner developers may not realize those points and may get stuck and give up.

If Django and google calendar API can be integrated, it can be applied to many web application developments such as scheduling apps, booking apps, etc. It would be a waste not to notice that point.

So in this article, I will explain the integration of Django and google calendar API through how to create a simple Django application, focusing on the "things to notice".

Application Structure

Development Process

To develop this application, the first step is to access the GCP(GoogleCloudPlatform) administration screen and obtain a credential file to communicate with the Google API.

We will develop this application in the following order:

1. Creating a Google API service account

Acquiring a GCP "Service Account" is crucial for this application. Using a Service Account is what makes this application possible. Previously, I attempted to build an app with a similar structure but repeatedly failed. I mistakenly believed I needed to connect a GCP user account to the calendar. However, that's not the case. To connect a Django application and the Google Calendar API, you need a Service Account within GCP, not a regular GCP user account. Once you obtain the Service Account, the rest of the implementation is straightforward.

1-1. The first step in using the Google API is to create a project. Click on the red frame above, enter a project name, and then create it.

1-2. After creating the project, select "IAM & ADMIN" from the Sidebar menu, and then choose "Service Account".

1-3. After selecting the service account, add the account service name and description.

1-4. During the development stage, you have the option to select "owner".

1-5. Now that we have a service account, we need to create a Key. Click on the part of the red frame to do so.

1-6. On the next screen, click the red frame and select "JSON". This will download the credential file to your local computer.

2. Creating a new calendar with Google calendar

3. Completing basic Django setup

Complete a basic Django project and application setup.

For reference,  this article will show you how to do a basic Django setup with Docker. This time, please proceed until step No.9 in that article.

Please note that no models will be made through this project.

4. Creating the first view

5. Creating a Form

6. Creating a template file

Next, let's create a template. In this template, the following three CDNs are added to the head section of base.html.

jQuery

jQuery DateTime Picker

Google fonts

Make sure to add jQuery and jQuery DateTime Picker. Google font is optional.

7. Writing Google API settings in `views.py`

8. Creating a POST Method in views.py

9. Retrieving Data from Google Calendar

10. Customizing the Design with CSS

That's all there is to it!

If you know how to communicate between your app and the API using a service account, I believe the scope of your app development will expand significantly.

Finally, the GitHub repository for this application is available here. Please make use of it in your web development.