Friday, October 2, 2020

Share your Google Calendar with a desktop app (written in node.js) using Google Calendar APIs

Use Case:

Alex is a busy social person and stores his calendar on Google calendar. He wants to be able to look at the highlights of what is coming up in text form. He is a geek and prefers command line interaction to view his calendar (his favorite editor is vi). He also wants to share his calendar with Sally. She is also a co-geek and wants to use a terminal to look at Alex's schedule. Alex want to be able to


   1) share his calendar with his pal Sally and only her

   2) viewable from a command line (say a terminal on my Macbook)


Google has made this fairly easy to do with a tutorial and clear instructions from the Google calendar API-enabler interface. Here is a quick walk of the process to enable Google calendar API.





Enable Google Calendar API

To start the process to enable Alex's calendar to be viewable by Sally (and in text form), Alex logs into his Google account and heads over to his Google cloud account (https://console.developers.google.com). He creates a new project, gives it a project name of "gcx". He decided that he will write the Google calendar client aka app - the reader from which he will invoke from the terminal - in Node.js for Sally. He follows the process to "enable Google Calendar API". This step will create credentials.json - which will have 1) Client ID and 2) Client Secret. This will help Google to know whose Google services to target - it this case, it will be Alb's.


Node.js App

To create the Node.js Google calendar reader, he found a useful sample code.  He sends that to Sally to use. Before she invokes it with "node index.js", she needs to use npm to install the Google calendar API SDK by typing "npm install googleapis@39 --save". If Sally skipped this step,  she will run into "Error: Cannot find module 'googleapis'".


App Asking Permission to Alex's Calendar

The first time the reader is invoked, it will contact Google. Google notes that this is an unverified application (a desk application via NODE.js to be specific) into Alex's calendar. Google wants to make sure that Alex is really ok sharing his social calendar with this reader. Google asks the user of the reader (Sally) to send to Alex a specific just created authentication link. That link will ask for Alex to log into his Google account to authorize the calendar reader to read his calendar. 


Alex Give Permission

Because Alex trusts Sally, he visits the link and clicks [v] View, then [Allow] to allow Sally's reader to use Google calendar API to read his calendar. Alb will receive an authorization code that he sends to Sally.  Sally will enter the authorization code, and viola, she can read Alb's calendar, on a terminal!


Conclusion 

Alex stores his social calendar in his Google calendar. He wants a way to share it with people he trusts (Sally), in the format they like to view in it (text on a terminal). Google calendar API can make this happen easily. 



No comments :

Post a Comment