5

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)

1 Answer 1

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);
  });
}
Sign up to request clarification or add additional context in comments.

3 Comments

Workerd fine... request.execute is not available in the request object only.
Any way to do it in batch? Let's say for 10 ids?
@ItzikGili Google has batch support for their APIs, but I'm not sure the Gmail API JavaScript client has it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.