Calendar Automation with Python using Google Calendar API and OAuth2 Authorization System

Calendar Automation with Python using Google Calendar API

There’s no doubt to say when we forget a date, we look for a calendar. In the last two decades, technology has evolved very rapidly and the digital calendar is vogue to stay productive. You may or may not stay on time but your calendar is always on time to remind you about your next event. It made our lives much easier to stay productive, time punctual, and efficient.

Google Calendar is the most commonly used calendar app that we use with over 1 Billion+ downloads. It tells how much people love using this app. You probably know that you can automate your Google calendar according to you. If not, don’t worry! In this article, I am going to tell step-wise-step to automate your own Google Calendar. If the idea excites you, there is a gift at the bottom.

What is Calendar Automation?

STEPS TO AUTOMATE YOUR GOOGLE CALENDAR

  1. First, we need to get credentials.json and for that follow below:
  • You need to have an OAuth consent screen which is very easy to do:

Visit Google Cloud Platform

GCP API Dashboard

Here create a new project name of your choice. Then go to the OAuth consent screen.

OAuth Screen
OAuth Consent screen

Here you have to choose the user type if you have a Google workspace account you have a choice to choose Internal. But for general choose external.

OAuth Screen
Fill out the details
Scope
Choose Scope

Choose the scope shown in the picture and continue, and then set your google account as a test user. Remember when you run the program, you must log in with your test email.

  • Now since you made an OAuth screen, get your API credentials.
Credentials
OAuth Client ID

Here you have to select OAuth client ID since we want to log in to our account to make it automated.

client ID
Client ID

Keep application type as a desktop app and give your app any client app.

json
Download JSON credential file

Now we are good to go to start programming our calendar automation app. Seems easy and fun right?

2. Now, we’ll start programming it

I suggest you use Pycharm because it makes it easy to set up the environment and install libraries. Create a folder name it according to you.

We will name our program files cal_setup.py and main.py. Also, move your credentials file into the folder you created and rename it. Here token.pickle file gets created automatically when we authorize the login, it gets stored to perform tasks without logging in over and over again. Open the folder in pycharm and create .py files named cal_setup.py and main.py. Let's code in three easy steps.

First, we need to install packages:

Package

Copy and paste the above command in your Pycharm terminal.

Copy the following code and paste it in cal_setup.py

cal_setup.py

Do not forget to move your credentials.json file. Otherwise, you have to give the path to the credential file.

Now, we made it to our third step. Copy the following and paste it in your main.py

Now, I hope you are reading this article. You can change the program if know Python. Remember do not to change anything in cal_setup.py. Though you can change time, hour, description &, etc. As I said there’s something special for you!

Below is the project repo, you can download it and run it if you do not want to program on your own. You still need to install the package.

This is licensed under MIT, please review the license before using, modifying, or replicating it.