I have to create a small program in NodeJS that will check the user's account for new messages and notify them via SMS (using Twilio) if they have new mail. Unfortunately, I'm having troubles getting the fetch functionality to work.
I have searched for a while and all snippets I could find have the same snippet as the one I'm posting below:
var gmail = google.gmail('v1');
//console.log("auth is " + util.inspect(auth, false, null));
// Line 77 under this comment
gmail.users.messages.list({userId: 'me', auth: auth}, function(err, response) {
console.log("this is " + util.inspect(response, false, null) + "with error " + err);
});
When this runs, it crashes with:
/Users/mirtle/Documents/Universishit/smsmirtle/node_modules/googleapis/lib/apirequest.js:180 req = authClient.request(options, callback); ^
TypeError: authClient.request is not a function at createAPIRequest (/Users/mirtle/Documents/Universishit/smsmirtle/node_modules/googleapis/lib/apirequest.js:180:22) at Object.Gmail.self.users.messages.list (/Users/mirtle/Documents/Universishit/smsmirtle/node_modules/googleapis/apis/gmail/v1.js:728:16) at CronJob. (/Users/mirtle/Documents/Universishit/smsmirtle/server.js:77:26) at CronJob.fireOnTick (/Users/mirtle/Documents/Universishit/smsmirtle/node_modules/cron/lib/cron.js:392:22) at callbackWrapper [as _onTimeout] (/Users/mirtle/Documents/Universishit/smsmirtle/node_modules/cron/lib/cron.js:435:9) at Timer.listOnTimeout (timers.js:92:15)
Like I said all snippets I could find, including from other StackOverflow questions, are like this so I don't know what I'm doing wrong here.
The auth token is valid. If you uncomment the comment above my Line 77 comment it prints it properly. It also runs the provided example by Google to print labels and they get printed, so the token is valid and authorised.
As a curiosity, if I call the function like this:
gmail.users.messages.list({}, function(err, response){...}
With no parameters, it doesn't crash, but it complaints there's no userId
.
I can also call it without the first parameter, but it also complaints about not having an userId
.
I will appreciate any help you can give.