javascript - Get messages in users' GMail inbox -


in code below signing in, authorising app, , getting console output via gmail api. believe getting threads , thread ids, not seeing messages in console.

i not getting errors , getting output, seems keys no values.

here console output looks like: enter image description here

here code:

var client_id = 'your_client_id'; var scopes = ['https://www.googleapis.com/auth/gmail.readonly']; var user = 'me';    /**    * called when client library loaded start auth flow.    */   function handleclientload() {     window.settimeout(checkauth, 1);   }    /**    * check if current user has authorized application.    */   function checkauth() {     gapi.auth.authorize(         {'client_id': client_id, 'scope': scopes, 'immediate': true},         handleauthresult);   }    /**    * called when authorization server replies.    *    * @param {object} authresult authorization result.    */   function handleauthresult(authresult) {     var authbutton = document.getelementbyid('authorizebutton');     var outputnotice = document.getelementbyid('notice');     authbutton.style.display = 'none';     outputnotice.style.display = 'block';     if (authresult && !authresult.error) {       // access token has been retrieved, requests can sent api.       gapi.client.load('gmail', 'v1', function() {         listthreads(user, function(resp) {           var threads = resp.threads;           (var = 0; < threads.length; i++) {             var thread = threads[i];             console.log(thread);             console.log(thread['id']);           }         });       });     } else {       // no access token retrieved, show button start authorization flow.       authbutton.style.display = 'block';       outputnotice.style.display = 'none';       authbutton.onclick = function() {           gapi.auth.authorize(               {'client_id': client_id, 'scope': scopes, 'immediate': false},               handleauthresult);       };     }   }     /**    * page of threads.    *    * @param  {string} userid user's email address. special value 'me'    * can used indicate authenticated user.    * @param  {function} callback function called when request complete.    */   function listthreads(userid, callback) {     var request = gapi.client.gmail.users.threads.list({       'userid': userid     });     request.execute(callback);   } 

how can retrieve address, subject, , body of messages? gmail api in js

**update: working with: **

listthreads('me', function(dataresult){     $.each(dataresult, function(i, item){         getthread('me', item.id, function(datamessage){             console.log(datamessage);             var temp = datamessage.messages[0].payload.headers;             $.each(temp, function(j, dataitem){                 if(dataitem.name == 'from'){                     console.log(dataitem.value);                 }             });          });       });    }); 

when log datamessage, 400 error, ' id required '. when log dataitem.value, datamessage.messages undefined , can not have index of 0.

i'd appreciate in getting working!

gmail api in javascript not explicit methods access particular email part - to/from/etc. gmail api in java has feature. gmail api in javascript still in beta. api list

you still wanna it: here outline:

instead of getting list of threads list of messages: message list

parse message id json retrieved previous call, use following: message get

get raw message in url encoded base64 format. decode , parse. safe encoding encoding

difficult... bet... :)


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -