I am trying to use the Gmail API to retrieve all thread entities in a gmail account.
This is easy with threads.list, but basically gets the identifier of the stream, not the object.
The only way I found is to use threads.list, then for each thread, calling threads.getand retrieving the object from the headers in the payload metadata.
Obviously this causes a lot of API calls, i.e. 101 calls if there are 100 threads.
Is there a better way?
Here is the code I'm using now:
var getIndivThread = function(threads) {
threads.threads.forEach(function(e) {
indivThreadRequst.id = e.id,
gmail.api.users.threads.get(indivThreadRequst).execute(showThread);
});
};
var indivThreadRequst= {
format: 'metadata',
metadataHeaders:['subject'],
userId: myUserId,
maxResults:1};
var showThread = function(thread) {
console.log(thread.messages[0].payload.headers[0].value);
};
gmail.api.users.threads.list({userId:myUserId}).execute(getIndivThread);
source
share