【问题标题】:nodejs gmail api not supporting promisesnodejs gmail api不支持承诺
【发布时间】:2018-05-04 03:36:39
【问题描述】:

Google recommends using promises,但它的代码示例没有,当我从 online docs 修改代码时,我正在努力使 gmail api 与 Promise 一起工作。

我只更改了以下几行,但出现错误

VM677:5 Uncaught TypeError: gmail.users.messages.list(...).then 不是函数

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);
})

大多数examples of SO 使用承诺,所以我认为这应该是可能的,但我看不出问题出在哪里。真的很欢迎一些帮助

【问题讨论】:

标签: node.js gmail-api


【解决方案1】:

googleapis 模块不支持承诺。

如果您想在此模块中使用 Promise,请考虑使用 util.promisify

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

list({
    auth: auth,
    userId: 'me',
    labelIds: 'Label_14'
})
.then(...);

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-12-27
  • 1970-01-01
  • 1970-01-01
  • 2019-09-29
  • 2019-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多