It does not seem to be documented by how does threads.get() and messages.get() sort the results they return.
Is the order by a descending date/time?
Id just like to say that using the javascript library -- messages.list does NOT return in date ASC or date DESC. They are returned randomly as far as I can tell.
At first I thought it may be my code since I was using jquery $.each to parse through the JSON but even using a native javascript for loop they are still not in Date order. It seems like the returned messages are mostly in date DESC, but every now and then one is thrown in out of order. I have done a fair amount of manipulation trying to diagnose, thinking...maybe these messages belong to the same thread...but this is not the case.
If anyone has a tip for the proper way to proceed using the javascript library please post. I'd rather deal simply with messages as my application is a simple record of rather than full CRUD on the messages...so just a simple list of messages in reverse date order is all I need.
ADDITION: I've also used threads.list and threads.get to return the messages and they are even more randomly sorted on the return. Really love for someone to post the proper way to retrieve messages sorted by date. Copied the code here for reference to any/all willing to take a look
function makeApiCall() {
gapi.client.load('gmail', 'v1', function() {
//console.log('inside call: '+myquery);
var request = gapi.client.gmail.users.threads.list({
'userId': 'me',
'q': myquery
});
request.execute(function(resp) {
//$('.ASAP-emailhouse').append(message+'<br>');
jQuery(document).ready(function($) {
var nummessages = resp.threads.length;
for (i = 0; i < resp.threads.length; i++) {
//$('.ASAP-emailhouse').append(resp.messages[i].id+'<br>');
var threadId = resp.threads[i].id;
var messagerequest = gapi.client.gmail.users.threads.get({
'userId': 'me',
'id': threadId
});//end var message request
messagerequest.execute(function(messageresp) {
for (m = 0; m < messageresp.messages.length; m++) {
//$('.ASAP-emailhouse').append(messageresp.messages[m].payload.headers.length+'<br>');
for (n = 0; n < messageresp.messages[m].payload.headers.length; n++) {
//$('.ASAP-emailhouse').append(messageresp.messages[m].payload.headers[n].name+'<br>');
if( messageresp.messages[m].payload.headers[n].name == 'Date'){
$('.ASAP-emailhouse').append(messageresp.messages[m].payload.headers[n].value+'<br>');
}
}
}
});
}//end for each message
});//end jquery wrapper for wordpress
});//end request execute list messages
});//end gapi client load gmail
}