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)來獲取差別部分。
相關文章
相關標籤/搜索