i am trying to read gmail inbox using google API in nodejs. but it return null value(messages), in this code im giving the message id directly copy from gmail inbox link
(function() {
'use strict';
var fs = require('fs');
var googleAuth = require('google-auth-library');
var google = require('googleapis');
function getOAuth2Client(cb) {
// Load client secrets
fs.readFile('client_secret.json', function(err, data) {
if (err) {
return cb(err);
}
var credentials = JSON.parse(data);
var clientSecret = credentials.installed.client_secret;
var clientId = credentials.installed.client_id;
var redirectUrl = credentials.installed.redirect_uris[0];
var auth = new googleAuth();
var oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);
// Load credentials
fs.readFile('gmail-credentials.json', function(err, token) {
if (err) {
return cb(err);
} else {
oauth2Client.credentials = JSON.parse(token);
return cb(null, oauth2Client);
}
});
});
}
function getMessage(auth) {
var gmail = google.gmail({ auth: auth, version: 'v1' });
gmail.users.messages.get({
'userId': 'me',
'id': '153a1f810aece662'
}, function (err, result) {
console.log(result);
});
}
getOAuth2Client(function(err, oauth2Client) {
if (err) {
console.log('err:', err);
} else {
console.log(oauth2Client);
getMessage(oauth2Client, function(err, results) {
if (err) {
console.log('err:', err);
} else {
console.log(results);
}
});
}
});
})();
the OAuth authentication data is perfectly worked but the null is return