【问题标题】:Getting Gmail Inbox using node.js and google-api使用 node.js 和 google-api 获取 Gmail 收件箱
【发布时间】:2016-05-23 16:46:21
【问题描述】:

我的代码如下,(以上代码与谷歌开发者网站中nodejs示例中给出的代码相同。)

function listLabels(auth) {

      var gmail = google.gmail({ auth: auth, version: 'v1' });

      var emails = gmail.users.messages.list({
          includeSpamTrash: false,
          maxResults: 500,
          q: "",
          userId: 'me'
      }, function (err, results) {
          console.log(results.messages);
      });
    }

我正在获取包含 ID 和 threadIds 的对象数组

现在,如果我输入这些 ID

进入这些

   function getMessage(messageId,auth) {
  var requestt = google.gmail({ auth: auth, version: 'v1' }).users.messages.get({
    'userId': 'me',
    'id': messageId
  });
  console.log(requestt)
  requestt.execute(function(response){
    console.log(response);
  });
}

我遇到了错误,

TypeError: requestt.execute is not a function
    at getMessage (/home/jay/Projects/gmailwebapi/index.js:122:11)
    at /home/jay/Projects/gmailwebapi/index.js:113:7
    at OAuth2Client._postRequest (/home/jay/Projects/gmailwebapi/node_modules/google-auth-library/lib/auth/oauth2client.js:381:3)
    at postRequestCb (/home/jay/Projects/gmailwebapi/node_modules/google-auth-library/lib/auth/oauth2client.js:343:10)
    at Request._callback (/home/jay/Projects/gmailwebapi/node_modules/google-auth-library/lib/transporters.js:103:7)
    at Request.self.callback (/home/jay/Projects/gmailwebapi/node_modules/google-auth-library/node_modules/request/request.js:198:22)
    at emitTwo (events.js:100:13)
    at Request.emit (events.js:185:7)
    at Request.<anonymous> (/home/jay/Projects/gmailwebapi/node_modules/google-auth-library/node_modules/request/request.js:1057:14)
    at emitOne (events.js:95:20)

【问题讨论】:

    标签: javascript node.js google-api gmail gmail-api


    【解决方案1】:

    您可以像列出消息时一样使用回调:

    function getMessage(messageId, auth) {
      var gmail = google.gmail({ auth: auth, version: 'v1' });
    
      gmail.users.messages.get({
        'userId': 'me',
        'id': messageId
      }, function (err, result) {
        console.log(result);
      });
    }
    

    【讨论】:

    • 工作人员很好... request.execute 仅在请求对象中不可用。
    • 有什么方法可以批量处理吗?假设有 10 个 ID?
    • @ItzikGili Google 的 API 有 batch support,但我不确定 Gmail API JavaScript 客户端是否有。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-30
    • 2015-04-07
    • 2014-12-19
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 2018-11-06
    相关资源
    最近更新 更多