Skip to content

Instantly share code, notes, and snippets.

@MichaelNahum
Last active May 29, 2018 18:17
Show Gist options
  • Save MichaelNahum/7621d7cd24c5a3961e9d51768f6b24e8 to your computer and use it in GitHub Desktop.
Save MichaelNahum/7621d7cd24c5a3961e9d51768f6b24e8 to your computer and use it in GitHub Desktop.
Promise Issue
function getMessage(userId, messageId, callback) {
let request = gapi.client.gmail.users.messages.get({
'userId': me,
'id': messageId
})
console.log(request)
request.execute(callback)
}
function listMessages(auth) {
const gmail = google.gmail({version: 'v1', auth});
gmail.users.messages.list({
userId: 'me',
}, (err, data) => {
let example = data.data.messages;
//console.log(example)
example.forEach(function(email) {
// console.log(email)
let emailId = email.id
}).then(getMessage(me, emailId, callback))
@Pugio
Copy link

Pugio commented May 29, 2018

function getMessage(gmail, messageId, callback) {
         console.log(messageId)
         console.log(callback)
         let request = gmail.users.messages.get({
           'userId': 'me',
           'id': messageId
         })
         request.execute(callback)
       }

function listMessages(auth) {
  const gmail = google.gmail({version: 'v1', auth});
  gmail.users.messages.list({
    userId: 'me',
  }, (err, data) => {
    let example = data.data.messages;
    //console.log(example)
    example.forEach(function(email) {
    //  console.log(email)
      let messageId = email.id
       getMessage(gmail, messageId, function (response) { console.log(response) }
    })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment