Gmail API push notification duplicate message ids

时间:2019-04-16 23:04:26

标签: google-api gmail-api

I am using Gmail push notifications for email processing. When I receive a message notification from Google, I use the history list API with the previously stored historyId and can see new messages using messagesAdded. Once I have retrieved the messages, I store the last historyId for the next request.

When testing, if I send two mail messages (about 30 seconds apart) to the watched mailbox, I see two messages notifications from Google and when I call the history API for each of the notifications I see the message ids. This is all good.

If I repeat the same test but send the two mail messages immediately after each other, I get the two notifications from Google but when I call the history API for the first message, I get the two message ids in that history API call. When I call the history API call for the second notification, I get a duplicate of the last message id.

How can I prevent seeing duplicate message ids in this scenario? Any help or pointers would be much appreciated.

Updated: Added request and response example for second test.

enter image description here

1 个答案:

答案 0 :(得分:0)

我在Google历史记录API的响应中注意到historyId显示了已处理的最新消息。如果我将此值存储为下一个起点而不是通知消息中发送的historyId,则它可以解决重复的问题,因为在第二个请求上不再有消息。不确定这样做是否正确,因为这表示我不存储或使用通知消息中发送的historyId