简体   繁体   English

Gmail API:无法请求未读邮件

[英]Gmail API : unable to request unread message

I post here because I'm learning to use Gmail API and I recently encountered a problem. 我在这里发帖是因为我正在学习使用Gmail API而且我最近遇到了一个问题。 When I try to list unread message with the following code 当我尝试使用以下代码列出未读消息时

var request = gapi.client.gmail.users.messages.list({
    'userId': 'me',
    'labelIds': 'INBOX',
    'q': 'is:unread'
});

I sometime get the right messages but sometimes not. 我有时得到正确的信息但有时却没有。 It's like gmail api does not have access to the immediate state of gmail and only synchronize every few minutes. 这就像gmail api无法访问gmail的即时状态,只能每隔几分钟同步一次。

An other example is that when i try to mark a message as read with 另一个例子是当我尝试将消息标记为已读时

var request = gapi.client.gmail.users.messages.modify({
    'userId': 'me',
    'id': id,
    'removeLabelIds': ['UNREAD']
});
request.execute(function (response) {
    console.log(response)
}

The response give that the label 'UNREAD doesn't exist for this message (and it is marked as read in Gmail web) but if I refresh my site, it loads the precedent message as unread. 响应表明此消息的标签“UNREAD”不存在(并且在Gmail网站中标记为已读取),但如果我刷新我的网站,则会将先前消息加载为未读。

It's driving me crazy because it worked two days ago and now it just not. 它让我发疯,因为它在两天前工作,现在却没有。

Any ideas ? 有任何想法吗 ?

EDIT 编辑

Clearing history between each request is fixing the problem but can't figure why ... 清除每个请求之间的历史记录是解决问题但无法理解为什么......

I tried those solutions but none worked Disable gmail api request caching 我试过那些解决方案,但没有工作禁用gmail api请求缓存

Try this code: 试试这段代码:

var request = gapi.client.gmail.users.messages.list({
    'userId': 'me',
    'labelIds': 'UNREAD'
});

request.execute(function(response) {    

    console.log(response);

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM