Open In App

Developing Unofficial Google Meet API in Node.js

Last Updated : 31 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

When it comes to virtual meetings, the easiest way that comes to mind is Google Meet, just generate the meeting link and send it to the participants. But doing it over and over again is frustrating, so in this article, we discuss how we can automate this process and make it a feature of our product/software.

How to automate this process?

So for this purpose, we can use Google Meet API but the problem with this is that it does not exist. Although we can do it with the help of google calendar API it’s a little bit difficult for a beginner to understand.

Let’s build an unofficial API for google meet which is limited to generating meeting links.

Things required for this process:

Enable calendar API:

  • Client Id
  • Client Secret
  • Refresh Token

Don’t worry if you don’t know how to enable Calendar API and how to get them all, check out the video or follow the steps below:

Step 1: Visit the official website of google cloud console https://console.cloud.google.com

Step 2: If you are having an existing project then select that or click on a new project.

Step 3: Select the library tab, search for the calendar API, and enable it.

Step 4: Select the credentials tab and create an OAuth client ID.

Now we have the client id and client secret but still, the refresh token is missing.

Follow the step-by-step process:

For the refresh token, we are going to use passportJS google auth2.0.

Step 1: Do npm install:

  • express 
  • passport and,
  • passport-google-oauth20
npm install express passport passport-google-oauth20

Step 2: Add “https://www.googleapis.com/auth/calendar” to the scope for getting the token which have the access to your google calendar.

Step 3: Add your client Id and client secret and run the application. Access the server through your web browser so by this way you can get the refresh token. If you are stuck somewhere you can also check out the above video.

Javascript




const express = require('express');
const app = express();
const port = 8000;
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
 
clientID = "XXXXX7762268-71s6k9joXXXXX2p0a55ba8li85jXXXXX.apps.googleusercontent.com"
clientSecret = "XXXXPX-iXaXXXXXjcoGsnqYQr0rDJeXXXXX"
 
passport.use(new GoogleStrategy({
    clientID: clientID,
    clientSecret: clientSecret,
},
    function (accessToken, refreshToken, profile, cb) {
        console.log("refreshToken : ", refreshToken)
        return cb();
    }
));
 
app.get('/auth/callback',
    passport.authenticate('google', { failureRedirect: '/' })
);
 
app.get('/auth',
    passport.authenticate('google', {
        scope: ['profile', 'https://www.googleapis.com/auth/calendar'],
        accessType: 'offline',
        prompt: 'consent'
    }
    ));
 
app.get('/', function (req, res) {
    res.send("done")
})
 
app.listen(port, function (err) {
    if (err) {
        console.log('something wrong in starting server !!!');
        return;
    }
    return console.log("server is up and running on port ", port);
});


Note

  • Replace the ‘X’ in the code with your Client Secret Key and Client ID to make it run.
  • After getting the refresh token you don’t need to do this process again and again.

Install one more npm package which was published by me google-meet-API and feed it all the details we have.

Javascript




const Meeting = require('google-meet-api').meet;
Meeting({
      clientId : 'XXXXdds420ghq7195tfsbi04i7rduaans.apps.googleusercontent.com',
    clientSecret : 'XXXXxxeh2mrCZ',
    refreshToken : 'XXXXXXXXXCNfW2MMGvJUSk4V7LplXAXXXX',
    date : "2020-12-01",
    time : "10:59",
    summary : 'summary',
    location : 'location',
    description : 'description'
    }).then(function(result){
    console.log(result);
})


Now the result is the final google meeting link here. Checkout full code here:

Github: https://github.com/sumitjangir123/Google-meeting-links

I’m assuming you enjoyed the article and found the material beneficial for your purposes.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads