How to get the number of unread threads in INBOX with Gmail API?

依然范特西╮ 提交于 2019-12-01 22:05:00

问题


I tried to use the list thread method:

GET https://www.googleapis.com/gmail/v1/users/{MyEmailAddress}/threads?labelIds=INBOX&labelIds=UNREAD&key={YOUR_API_KEY}

The resultSizeEstimate does not match the number next to my inbox in Gmail web app.

Is there another way?


回答1:


The Gmail API now provides total and unread counts for messages and threads on each Label using the Labels.Get() method. See: https://developers.google.com/gmail/api/release-notes and https://developers.google.com/gmail/api/v1/reference/users/labels




回答2:


Turn conversation view off in the Gmail UI in order to get an accurate count of the message (not threads) in your inbox.

You can also use:

in:inbox is:unread

as the query in both the UI and API. Remove the labelId parameters.




回答3:


GET https://www.googleapis.com/gmail/v1/users/{email}/messages?labelIds=UNREAD&labelIds=INBOX&fields=messages%2FthreadId

"messages/threadId" will count the number of unread threads but will list the same thread multiple times if the thread has multiple messages. Store them in an array and check the array as you fill it for matching "threadId" identifiers and ignore duplicates.



来源:https://stackoverflow.com/questions/24468457/how-to-get-the-number-of-unread-threads-in-inbox-with-gmail-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!