I am doing WEB HTTP calls using Gmail API. Is there a way to batch get message content?
It seems that messages.list only returns messageIds, and messages.get only support single message query.
LIST API: https://www.googleapis.com/gmail/v1/users/userId/messages GET API: https://www.googleapis.com/gmail/v1/users/userId/messages/id
Help me guys~ Thank you!
You can definitely do batched messages.get(), quite a few questions covering it already: https://stackoverflow.com/search?q=%5Bgmail-api%5D+batch
The gmail API returns only messageId
s first to prevent heavy load.
With those Ids you can get individual full messages or send a batch request for getting a bunch of messages.
After getting the partialMessages(message ids)
use this :
List<Messages> fullMessages = getFullyQualifiedMessages(partialMessages);
private List<Message> getFullyQualifiedMessages(List<Message> partialMessages) {
try {
final JsonBatchCallback<Message> callback = new JsonBatchCallback<Message>() {
public void onSuccess(Message message, HttpHeaders responseHeaders) {
fullyQualifiedMessageList.add(message);
}
public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
// do what you want if error occurs
}
};
BatchRequest batch = mService.batch();
for (Message message : partialMessages) {
mService.users().messages().get("me", message.getId()).setFormat("full").queue(batch, callback);
}
batch.execute();
} catch (IOException e) {
e.printStackTrace();
}
Log.d(TAG, "Message" + fullyQualifiedMessageList.size());
return fullyQualifiedMessageList;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With