Gmail API:仅观看收件箱标签 [英] Gmail API: Watch Inbox label Only

查看:95
本文介绍了Gmail API:仅观看收件箱标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码来查看邮箱.如图所示,在lableIds中,我只有一个标签INBOX,因为我只想听新消息.但是,当我运行此命令时,它每隔30秒左右就会收到带有不同messageid的通知.但是收件箱中没有发生任何变化,没有添加/删除新项目.如何将手表主体设置为仅收听INBOX的传入消息?

I have the code below to watch a mailbox. As seen, in the lableIds, I only have one label, INBOX because I want to listen to only new messages. However, when I run this, it receives notifications every 30s or so with different messageid. Yet no change occurred in the INBOX, no new item was added/removed. How do I set my watch body to only listen to the INBOX for incoming messages?

certificate= new X509Certificate2("file.p12"), "password",     
X509KeyStorageFlags.Exportable);
credential = new ServiceAccountCredential(
                   new ServiceAccountCredential.Initializer(serviceaccount)
                   {
                       User = username,//username being impersonated
                       Scopes = scopes
                   }.FromCertificate(certificate));
var service = new GmailService(new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = applicationame,
    });


WatchRequest body = new WatchRequest()
{
    TopicName = "projects/projectid/topics/topicname",
    LabelIds = new[] {"INBOX"}
}
string userId = "me";
UsersResource.WatchRequest watchRequest = service.Users.Watch(body, userId);
WatchResponse test = watchRequest.Execute();

推荐答案

Gmail显然会忽略请求的过滤器数据.这似乎是gmail内部的已知错误.检出 https://issuetracker.google.com/issues/37300052 来监视进度,尽管它可以似乎很安静.我建议填写错误报告,这样至少可以重复一遍.

Gmail apparently ignores the requested filter data. This looks to be a known bug inside gmail. Checkout https://issuetracker.google.com/issues/37300052 to monitor progress, although it seems to be pretty quiet. I'd recommend filling out the bug report so it's at least repeated.

对于我的用例,我只在寻找带有特定自定义标签的电子邮件.可以存储该用户的历史记录ID(请参见 https: //developers.google.com/gmail/api/v1/reference/users/history/list ),由于那是一个纪元,因此只能每隔X分钟左右调用一次gmail api.这样可以减少您拨打gmail的电话数量,但这并不完美.

For my use case, I'm looking only for emails with a specific, custom label. It's possible to store the history id for that user (see https://developers.google.com/gmail/api/v1/reference/users/history/list), and since that's an epoch, only call the gmail api every X minutes or so. This reduces the number of calls you're making to gmail, but isn't perfect.

这篇关于Gmail API:仅观看收件箱标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆