How to get holidays with CURL


Please Share

Do you have an application that needs to display holidays to your users? Are you having issues finding holidays for different countries. Well this post is going to help you do that.

Today we are going to see how to request holidays from the Google Calendar API using an api key with curl. An Api key is a unique identifier required by Google when making calls to their APIs.

Creating an api key

Api keys are used by Google to identify your application, they are mainly used when accessing public data. In order to follow along with this tutorial you will need your own api key.

If you would like to learn more about API keys as well as how to create your own please check my other blog post on Google developer console API keys or the companion video for that post How to create an api key, fast!

Calendar id

This method will work with any google calendar which has been set to public, in this example we will be using one of the google calendar holiday calendars. You will need to go to the Google calendar web app and find the calendar id in the settings for the calendar you wish to get the events for.

if you are having issues in finding the calendar id you can check the companion video for this post which shows you exactly how to find it

Code

The first thing we do is call the endpoint for the Google calendar event list method We need to pass it the calendar id of the calendar we want to find events from. Finally we give it our api key.


curl \
  'https://www.googleapis.com/calendar/v3/calendars/[calendar id]/events?key=[API KEY]' \
  --header 'Accept: application/json' \
  --compressed

Putting it all together should look something like this.


curl \
  'https://www.googleapis.com/calendar/v3/calendars/en.danish%23holiday%40group.v.calendar.google.com/events?key=AIzaSyAaXxI53pCVT7WAGqC3ZzGWndrvuha80eQ' \
  --header 'Accept: application/json' \
  --compressed

Conclusion

Google calendar offers a number of public calendars that we can access, as they are public we don’t need to use Oauth2 in order to authorize a user we can use a public api key. Public api keys give us read only access, they will not allow us to write to the calendar even if the calendar is set to public.

Please Share


About Linda Lawton

My name is Linda Lawton I have more than 20 years experience working as an application developer and a database expert. I have also been working with Google APIs since 2012 and I have been contributing to the Google .Net client library since 2013. In 2013 I became a a Google Developer Experts for Google Analytics.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.