With the GMail API, what's the preferred way to get new messages?

1.3k views Asked by At

The app I'm making needs to monitor the Inbox for new messages. As far as I am aware, there is no way yet for the GMail API to push a notif to me when a user has a new message (Push notification for new gmail).

I could check every minute for new messages by using the history IDs. Is that the current best method outside of implementing a full IMAP solution (which would no longer be utilizing the GMail API)?

1

There are 1 answers

0
Jay Lee On

The most efficient Gmail API method would be to use history.list(). Specify a labelId of Inbox (so you're not seeing updates on other labels) and a historyId of whatever the largest historyId you've previously seen is (you'll need to track this). If you get back a 404 error, you'll need to use messages.list() instead to perform a full sync.