Gmail API:仅限观看收件箱标签

时间:2017-04-10 18:29:12

标签: c# gmail-api google-cloud-pubsub

我有以下代码来观看邮箱。如图所示,在lableIds中,我只有一个标签,INBOX因为我只想听新消息。但是,当我运行它时,它会使用不同的messageid每30秒左右收到一次通知。然而,INBOX没有发生任何变化,没有添加/删除新项目。如何将我的手表机身设置为仅收听INBOX收到的消息?

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();

1 个答案:

答案 0 :(得分:2)

Gmail显然忽略了请求的过滤数据。这看起来是gmail中的一个已知错误。结帐https://issuetracker.google.com/issues/37300052来监控进度,虽然看起来很安静。我建议填写错误报告,以便至少重复一次。

对于我的用例,我只关注具有特定自定义标签的电子邮件。可以存储该用户的历史ID(请参阅https://developers.google.com/gmail/api/v1/reference/users/history/list),因为这是一个纪元,所以每隔X分钟左右只调用一次gmail api。这减少了你对gmail进行的通话次数,但并不完美。

相关问题