I need to get the last 100 messages in the INBOX (headers only). For that I'm currently using the IMAP extension to search and then fetch the messages. This is done with two requests (SEARCH
and then UID FETCH
).
What's the Gmail API equivalent to fetching multiple messages in one request?
All I could find is a batch API, which seems way more cumbersome (composing a long list of messages:get
requests wrapped in plain HTTP code).
相关问题
- Token invalid - Invalid token: Cannot parse referr
- Getting error in Mail send Using Nodemailer
- How do I batch send a multipart html post with mul
- Gmail (for business) API doesn't allow to send
- Gmail Api Create Draft Reply
相关文章
- Insufficient Permission [403] error while modifyin
- failedPrecondition error when authenticating with
- Understanding Gmail api quotas
- iOS - Send an email automatically (NOT from user
- Error 400 when sending a message using python
- java.lang.NoSuchMethodError: No static method isAt
- How to extract full body content of a Bounced back
- GMAIL API sending email with attachment in c#
Great reply!
If somebody wants to use a raw function in php to make batch requests for fetching emails corresponding to message ids, please feel free to use mine.
FYI the above function gets just the headers for the emails, in particular the From and Date fields, please adjust according to the api documentation https://developers.google.com/gmail/api/v1/reference/users/messages/get
In addition to MaK you can perform multiple batch requests using the google-api-php-client and
Google_Http_Batch()
here is the python version, using the official google api client. Note that I did not use the callback here, because I need to handle the responses in a synchronous way.
It's pretty much the same in the Gmail API as in IMAP. Two requests: first is messages.list to get the message ids. Then a (batched) message.get to retrieve the ones you want. Depending on what language you're using the client libraries may help with the batch request construction.
From: https://developers.google.com/storage/docs/json_api/v1/how-tos/batch
It's really not that hard, took me about an hour to figure it out in python even without the python client libraries (just using httplib and mimelib).
Here's a partial code snippet of doing it, again with direct python. Hopefully it makes it clear that's there's not too much involved: