Google Apps - Gmail API的通知功能

###Gmail API Google终于提供了Gmail Push Notification功能了。 Synchronizing Clients with Gmailios

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.api

正如Google所说,以前咱们为了同步用户的邮件信息或者新邮件通知的时候,服务器端须要不停的去Google调用用户当前的邮件信息。如今经过它新提供的push notification功能,服务器不须要主动去获取,而是只须要在那等待Google主动发送请求到咱们服务器上便可。服务器

###注意事项 在同步邮件的时候须要注意下面几个方面:app

  • 首次须要全局同步,利用message.list,batch requestmessage.get来同步用户的所有邮件信息。
  • 以后利用Users.watch开启监听并获取最新的historyId并保存到本地
  • 当Google主动push一个请求过来时,判断得到的historyId是否比Client.historyId新。若是是的话,就经过Users.history.list(Client.historyId)来获取差别部分。
相关文章
相关标签/搜索