DEV Community

Cover image for Google Calendar API Integration Made Easy

Google Calendar API Integration Made Easy

megazear7 on July 08, 2019

I recently struggled to integrate the Google Calendar API while trying to create an event listing for a website. While in retrospect most of it sho...
Collapse
 
juniorgodoi profile image
Junior Godoi

Hello, trying this code and getting:

{"error":{"library":"PEM routines","function":"get_name","reason":"no start line","code":"ERR_OSSL_PEM_NO_START_LINE"}}

Can't figure out why, all the settings are correct and calendar is shared with the correct service account.

Collapse
 
ksbeasle profile image
Kahlil Beasley

Hi, don't know if you already figured it out but for you or anyone else running into the same issue I solved it by doing the following.

  1. Put the entire jwt json file you get from google into an env variable in the .env file.
    example: SOME_VAR='{"key": "value"}'
    NOTE The entire json file has to be on a single line

  2. Then read in the value in your index.js file
    example: const { SOME_VAR } = process.env; //JSON

3.Parse it.
example: const someVar = JSON.parse(SOME_VAR);

  1. Use dot notation to access that key and pass it wherever you need it. example: someVar.key // 'value'
Collapse
 
james6m profile image
James McLean

This is great. So much of the documentation out there assumes that you want to access /other/ people's calendars.
At step 4 of "Setup JWT Access", I do not get a JSON file download. There are a bunch of fields to fill out, including granting access to the project with a bewildering array of access options. Is that expected and just glossed over in these instructions? What access roles to choose?

Collapse
 
megazear7 profile image
megazear7

This article is specifically designed for the "server to server" authentication scenario. This means that your express server communicates with the Google API with authorization that has been setup ahead of time.

The scenario that you are describing is where a user gives certain authorizations to your app in order to do things such as add events to the users calendar. This would be where the user would see the " wants to add events to your calendar" and the user would say yes. At this point your app would receive a token to use in order to authenticate with the google API for that user.

While it is outside the scope of a comment to explain this in more detail, I hope this at least gets you on the right track.

Collapse
 
vitality82 profile image
vitality82 • Edited

I'm also very interested in this scenario. Some apps will have just have a one-time connect with google calendar (OAuth + consent) and from there on, any events created in that app will show up on my calendar, or on any users google calendars within that app.

I don't see how this could be automated as if you imported a webcal URL into google. I assume each time your application created an event it needs to push that event to all your users calendars (who already autorized your app) or, there is just one syncing server (Google CalDAV?) that your application can push events to, and that server knows how to update client calendars?

Thread Thread
 
megazear7 profile image
megazear7

This is specifically designed to integrate an "administrated calendar" into a website. So this doesn't display user data, it displays data from a calendar that is administered behind the scenes and then displayed on a website.

Thread Thread
 
vitality82 profile image
vitality82

Thanks!

Collapse
 
shaikabbas051 profile image
shaik abbas

Can we make other people as an organizer of the meeting?

Collapse
 
vikramchandra profile image
Vikram Sharma

Hi. Thanks for the detailed tut. For those interested in looking at other options, here is a list of calendar apis.

Collapse
 
sarang87 profile image
Sarang Joshi

Is it possible to post events on someone else's calendar? If so how would these permissions be enabled to allow posting or getting data from other people's calenders?

Collapse
 
zeealik profile image
Zeeshan Ali Khan

How can we integrate this with a ReactJS application?
Using the MERN stack?

Collapse
 
jmbodz profile image
JMBodz

Hello, is there a way to get the response from the invitee when an event was sent using this googlecalendarapi?