Efficient way of syncing Gmail Inbox messages using the new Gmail API?

隐身守侯 提交于 2019-12-08 13:54:20

问题


A web application sends an email on behalf of a UserA to UserB, using the new Gmail API (Users.messages: send).

The synchronous response contains threadId, messageId which are stored in the database.

We then query the history API for any changes in user's inbox (Users.history: list).

Is there an efficient way to get all the updates since last sync (new replies, read/unread changes)?

One implementation that we tried was to filter the history API results through a custom label. Unfortunately, we noticed that once a thread/message is tagged with a specific label any subsequent responses are not labeled automatically and new replies are not included in the history API response.

A second approach was to query threads using gmail advanced search for a particular label and date (e.g. after:2014/08/29 label:MY_LABEL). The problem was that gmail does not return threads that were created before 2014/08/29 but had a reply on that date.

Any scalable suggestions would be greatly appreciated.


回答1:


Not sure I understand here, users.history.list was made exactly for this. Given a previous historyId, you can then call history.list(previousHistoryid), iterate through the results to find all the message Ids that have been updated since the previous historyId. Then call messages.get() on all of those--for any messages you already knew about you can just call format=MINIMAL (to see label updates), and for new messages you can use a different format to get the message content if you need it.



来源:https://stackoverflow.com/questions/25571679/efficient-way-of-syncing-gmail-inbox-messages-using-the-new-gmail-api

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