Gmail API all messages

你说的曾经没有我的故事 提交于 2019-12-01 06:12:14

Use batch and request 100 messages at a time. You will need to make 1000 requests but the good news is that's quite fine and it'll be easier for everyone (no downloading 1GB response in a single request!).

Documented at: https://developers.google.com/gmail/api/guides/batch

There's a few other people that have asked about batching Gmail Api here on Stack Overflow, so just do a quick search to find answers and examples.

The approach you are doing is correct, as there is no 'GetAll' API to download them

Reasons include:

Unbounded Result Sets

Pulling out an unlimited amount of emails (aka unbounded result set) is a resource hog on Google servers. Did you want the attachments AND images? These could be gigabytes of data.

Network Problems

Google has to read gigabytes form disk, store it in memory and send them over the internet. Google's server would handle it, but the bandwidth of internet connectivity would not work. Worst of all, if you issue this request again and again, you could perform a DDoS attack on Google.

Security Risk

If someone gains an API key of another user, they could download their entire mailbox. Hence Google provide paging to ensure that they can provide a securer service and reduce resource contention.

Therefore, it is there to protect you and other users, and themselves.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!