Gmail API: Watch Inbox label Only

自古美人都是妖i 提交于 2019-12-24 08:50:09

问题


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

回答1:


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.

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.



来源:https://stackoverflow.com/questions/43330396/gmail-api-watch-inbox-label-only

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