Flutter: Use Google Calendar API— Fetching Events from Public Google Calendar

Hamza Azam
4 min readFeb 9, 2020

--

Edit

This article shows Setting up Google Calendar API to show EVENTS that are made on a public Calendar.

You can find articles on Inserting, Deleting and retrieving Events from/to User’s Calendar after retrieving Google Oauth 2.0 access credentials over here.

Introduction:

Google Calendar API can help to Get, Delete, Create events and many other things.

I am going to write steps to show how to use Google Calendar API in your Flutter Application to show your Google Calendar (of Public Calendar) Events on your Flutter Application.

Part 1 Setting up the Google Calendar API

Part 2 Getting and showing the Google Calendar Events in flutter Application

This article will help you to set up the Google Console Project. And use it to get events from Google Calendar that is made public.

Things to do before Code:

1 — Go to Google APIs dashboard https://console.developers.google.com/.

2 — Login through your Gmail account. (If you are already logged in then you may not need to log in again)

You will be now at dashboard like the following picture

3 — Click the My Project (don’t worry if you see some other name).

You will see the list of all Projects.

4 — Create a new Project

5 — You can create a new Project here.

Note: You may see some warning like this You have 2 projects remaining in your quota. Request an increase or delete projects. This is the limit of the project that google clouds provide a user to create. Of course, you can increase it by requesting them.

You may see error You’ve reached your project limit. You can create more projects after you request a project limit increase. That means you have used your all limits. Now either requests them or delete at least one previous project to create a new project.

6 — After Creating, you will be returned to dashboard. Confirm that the name of project is similar to that you have created. If not open the list of all projects by clicking here and Selecting your desired Project

7 — Click ENABLE APIS AND SERVICES

8 — Search for Google Calendar API. And open it.

9 — Enable This API

10 — Return to your Dashboard.

11 — Click on Credentials

12 — Click on Create Credentials. Then on API KEY. It will create API. You may want to restrict the usage of API Key I won’t be restricting it.

The API KEY will be like AIzaSyCy81D****************************

DO NOT share this KEY WITH Anyone.

Now Copy the API KEY and use the following url to access the JSON Object of your Google Calendar. Paste it in your browser.

https://www.googleapis.com/calendar/v3/calendars/{YOUR CALENDARID WITHOUT CURLY BRACES}/events?key={YOUR KEY WITHOUT CURLY BRACES}

BUT You may get error like this

This error means your Calendar is private. Go to settings and make your Calendar PUBLIC. But Remember this will expose your calendar to google search also.

You may want to only authorize people to access it. Then you will need to restrict API credentials and make authorized requests. That’s not our topic right now. I will discuss it in my later articles

I̶n̶ ̶n̶e̶x̶t̶ ̶P̶a̶r̶t̶.̶ ̶I̶ ̶w̶i̶l̶l̶ ̶s̶h̶o̶w̶ ̶h̶o̶w̶ ̶u̶s̶e̶ ̶t̶h̶i̶s̶ ̶A̶P̶I̶ ̶i̶n̶ ̶y̶o̶u̶r̶ ̶f̶l̶u̶t̶t̶e̶r̶ ̶a̶p̶p̶l̶i̶c̶a̶t̶i̶o̶n̶.̶

Correction

There will be no next part of this article since you can find a lot of articles, tutorials on parsing JSON data in Flutter. Here is a great resource of parsing JSON in Flutter

But You can find articles on Inserting, Deleting and retrieving Events from/to User’s Calendar after retrieving Google Oauth 2.0 access credentials over here.

Thanks for reading my article so far, please give me your feedback.

--

--