[英]Check if mail is read, gmail api
I am working on a gmail app (you can probably tell if you read my other questions), I can list my first 10 email, however I have no way of knowing weather they are read or not. 我正在开发一个gmail应用程序(您可能会告诉您是否阅读了其他问题),我可以列出我的前10封电子邮件,但是我无法知道他们是否被阅读。 Does anyone know how I would even go about this? 有人知道我什至会怎么做吗? Thanks! 谢谢!
If I list my newest message: 如果我列出最新消息:
GET https://www.googleapis.com/gmail/v1/users/me/messages?maxResults=1&access_token={ACCESS_TOKEN}
{
"messages": [
{
"id": "158d822014b7887b",
"threadId": "158d822014b7887b"
}
],
"nextPageToken": "17683191771541399341",
"resultSizeEstimate": 2
}
And then get the message: 然后得到消息:
GET https://www.googleapis.com/gmail/v1/users/me/messages/158d822014b7887b?format=metadata&access_token={ACCESS_TOKEN}
{
"id": "158d822014b7887b",
"threadId": "158d822014b7887b",
"labelIds": [
"UNREAD",
"CATEGORY_SOCIAL",
"INBOX"
],
...
}
You can see that the message has a labelId
with the value of UNREAD
. 您可以看到该消息的labelId
值为UNREAD
。 If the message doesn't have this labelId
, it is read. 如果消息没有此labelId
,则将其读取。
var isRead = message.labelIds.indexOf("UNREAD") === -1;
just for anyone else that wants to do this here is a simple piece of code that will do it. 对于任何想这样做的人来说,这都是一件简单的代码即可。
if (message.labelIds[0] === 'UNREAD'){
//do somthing
}
Use the following request to only fetch unread messages 使用以下请求仅获取未读消息
GET https://www.googleapis.com/gmail/v1/users/me/messages?q=is:unread&maxResults=1&access_token={ACCESS_TOKEN}
Reference: https://support.google.com/mail/answer/7190?hl=en 参考: https : //support.google.com/mail/answer/7190?hl=zh_CN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.