Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs gmail api not supporting promises

Google recommends using promises, but its code examples do not, and I'm struggling to make the gmail api work with promises when I modify the code from the online docs.

All I've changed are the lines below, but I get an error

VM677:5 Uncaught TypeError: gmail.users.messages.list(...).then is not a function

gmail.users.messages.list({
    auth: auth,
    userId: 'me',
    labelIds: 'Label_14'
// }, function(err, response) {
//     if (err) {
//         console.log('The API returned an error: ' + err);
//         return;
//     }
//     console.log(response);
})
.then(response => {
    console.log("success", response);
})

Most of the examples of SO use promises so I think it should be possible but I can't see what the problem is. Would really welcome some help

like image 526
Simon H Avatar asked May 15 '26 05:05

Simon H


1 Answers

The googleapis module does not support promises.

Consider using util.promisify if you want to use promises with this module.

var list = util.promisify(gmail.users.messages.list);

list({
    auth: auth,
    userId: 'me',
    labelIds: 'Label_14'
})
.then(...);
like image 111
josh3736 Avatar answered May 19 '26 03:05

josh3736



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!