最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Getting Gmail Inbox using node.js and google-api - Stack Overflow

programmeradmin0浏览0评论

My Code follows,(above code is same as given in the example of nodejs in google developer site.)

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

I'm getting array of objects containing IDs and threadIds

Now, if i input these IDs

into these

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

I am getting error,

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)

My Code follows,(above code is same as given in the example of nodejs in google developer site.)

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

I'm getting array of objects containing IDs and threadIds

Now, if i input these IDs

into these

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

I am getting error,

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)
Share Improve this question edited Feb 12, 2016 at 13:56 scarecrow asked Feb 12, 2016 at 13:48 scarecrowscarecrow 1,6151 gold badge18 silver badges22 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You could use the callback the same way you do when you list messages:

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);
  });
}
发布评论

评论列表(0)

  1. 暂无评论