nodejs gmail api不支持promise [英] nodejs gmail api not supporting promises
问题描述
Google 建议使用Promise ,但其代码示例否,当我从
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未被捕获的TypeError:gmail.users.messages.list(...).然后不是函数
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);
})
大多数 SO的示例使用诺言,所以我认为应该有可能,但我看不出问题出在哪里.真的会欢迎您的帮助
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
推荐答案
googleapis
模块不支持promise.
The googleapis
module does not support promises.
考虑使用 util.promisify
在此模块中使用诺言.
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(...);
这篇关于nodejs gmail api不支持promise的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!