nodejs如何获取gmail原始消息? [英] nodejs How to get gmail raw messages?

查看:97
本文介绍了nodejs如何获取gmail原始消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 gmail API参考.但是它似乎不起作用.下面是我的代码:

I am trying to get the full email message data with body content using the raw option of the format as described in the gmail api reference. How ever it doesn't seem to work. Below is my code:

function listMessages(auth) {
  var gmail = google.gmail('v1');
  var nextPageToken = null;

  gmail.users.messages.list({
    auth: auth,
    userId: 'me',
    pageToken: nextPageToken,
    q: ''
  }, function(err, response) {
    if (err) {
      console.log('The API returned an error: ' + err);
      return;
    }

    var msgs = response.messages;
    if (msgs.length == 0) {
      console.log('No messages found.');
    } else {
      console.log('Messages:');
      the_format = 'raw';
      for (var i = 0; i < msgs.length; i++) {
        var msg = msgs[i];
        console.log('- %s', msg.id);
        gmail.users.messages.get({
          auth: auth,
          userId: 'me',
          id: msg.id,
          format: the_format,
        }, function(err, response) {
          if (err) {
             console.log('The API returned an error: ' + err);
             return;
          }

          console.log(response);

        });
      }
    }
  });
}

这是返回结果的示例.我看不到原始字段,更改格式"(原始或最小)时总是返回相同的结果.

And here is an example of a returned result. I don't see the raw fields and the same result is always returned when I change the 'format' (raw or minimal).

我在这里想念什么?

{ id: '16xxxxxxxxxxxxxxxxxx',
  threadId: '161xxxxxxxxxxxxxxxx',
  labelIds: [ 'UNREAD', 'Label_44', 'CATEGORY_UPDATES' ],
  snippet: 'atom posted: &quot;Voici le 9e volet de notre rubrique À quoi tu joues ? Aujourd&#39;hui la Testing Team vous embarque au Japon, avec Sakura. S&#39;est perdu dans un manoir infernal, ou a défendu un',
  historyId: '11336356',
  internalDate: '1516xxxxxxxxx',
  payload:
   { partId: '',
     mimeType: 'multipart/alternative',
     filename: '',
     headers:
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ],
     body: { size: 0 },
     parts: [ [Object], [Object] ] },
  sizeEstimate: 98391 }

推荐答案

您需要使用:

var msgs = response.data.messages;

代替:

var msgs = response.messages;

就是这样.

这篇关于nodejs如何获取gmail原始消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆