###Gmail API Google终于提供了Gmail Push Notification功能了。 Synchronizing Clients with Gmail
Keeping your client synchronized with Gmail is important for most application scenarios. There are two overall synchronization scenarios: full synchronization and partial synchronization. Full synchronization is required the first time your client connects to Gmail and in some other rare scenarios. If your client has recently synchronized, partial synchronization is a lighter-weight alternative to a full sync. You can also use push notifications to trigger partial synchronization in real-time and only when necessary, thereby avoiding needless polling.
正如Google所说,之前我们为了同步用户的邮件信息或者新邮件通知的时候,服务器端需要不停的去Google调用用户当前的邮件信息。现在通过它新提供的push notification功能,服务器不需要主动去获取,而是只需要在那等待Google主动发送请求到我们服务器上即可。
###注意事项 在同步邮件的时候需要注意下面几个方面:
- 首次需要全局同步,利用
message.list
,batch request
和message.get
来同步用户的全部邮件信息。 - 之后利用
Users.watch
开启监听并获取最新的historyId并保存到本地 - 当Google主动push一个请求过来时,判断获得的historyId是否比Client.historyId新。如果是的话,就通过
Users.history.list(Client.historyId)
来获取差异部分。