使用新的Gmail API同步Gmail收件箱邮件的有效方式? [英] Efficient way of syncing Gmail Inbox messages using the new Gmail API?

查看:150
本文介绍了使用新的Gmail API同步Gmail收件箱邮件的有效方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Web应用程序使用新的Gmail API( Users.messages:send )向 UserA 发送电子邮件至 UserB EM> )。

同步响应包含存储在数据库中的 threadId messageId 。然后我们查询历史API以查看用户收件箱中的任何更改( Users.history:list )。 / p>

有没有一种有效的方法可以获得自上次同步以来的所有更新(新回复,读取/未读更改)?

<我们尝试的一个实现是通过自定义标签过滤历史API结果。不幸的是,我们注意到,一旦线程/消息被标记了特定标签,任何后续响应都不会自动标记,并且新的答复不会包含在历史API响应中。



第二种方法是使用gmail高级搜索查询特定标签和日期的线程(例如:2014/08/29 label:MY_LABEL)。问题在于gmail不会返回2014/08/29之前创建的线程,但在该日期有回复。



任何可扩展的建议将不胜感激。 / p>

解决方案

不知道我在这里明白,users.history.list正是为此而做的。给定一个以前的historyId,然后你可以调用history.list(previousHistoryid),遍历结果来查找自上一个historyId以来已经更新的所有消息ID。然后在所有这些消息上调用messages.get() - 对于您已知的任何消息,只需调用format = MINIMAL(查看标签更新);对于新消息,您可以使用其他格式获取消息内容if你需要它。


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.

解决方案

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.

这篇关于使用新的Gmail API同步Gmail收件箱邮件的有效方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆