Sunday 11 June 2017

"Error, Connect 500 TypeError: Cannot read property 'gmail' of undefined" -- Trying to use GMail API with Node.js

Very similar to this question asked here, TypeError: Cannot read property 'gmail' of undefined, but very little information was provided to solve the issue.

I'm getting this error, "Connect 500 TypeError: Cannot read property 'gmail' of undefined", when trying to load the page with the following code.

var fs = require('fs');
var readline = require('readline');
var google = require('googleapis');
var gapi = require('gapi');
var gmail = google.gmail('v1');


function listLabels(userId, callback) {
  console.log(userId)
  var request = gapi.client.gmail.users.labels.list({
    'userId': userId
  });
  request.execute(function(resp) {
    var labels = resp.labels;
    callback(labels);
  });
}


exports.index = (req, res) => {

  listLabels(req.user.email)
  //findMessages()
  res.render('home', {
    title: 'Home'
  });
};

I believe I was able to get authenticated properly, as I was able to save my token to my user's profile. Screenshot of mongodb user entry.

Any help or guidance will be greatly appreciated :)



via Crystal Wesnoski

No comments:

Post a Comment