Gmail API Watch未按标签过滤 [英] Gmail API Watch not filtering by Label

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

问题描述

我正在将Gmail推送通知与Google PubSub一起使用,并且有一个自定义标签,我想对其进行任何更改进行监视.我使用以下代码为标签注册手表(标签的ID为Label_1)

I am using Gmail Push Notifications with Google PubSub and have a custom label that I want to monitor for any changes. I use the following code to register a watch for the label (Id of the label is Label_1)

WatchRequest wr = new WatchRequest();
wr.TopicName = "projects/" + primaryLink.ggProjectId + "/topics/iLink" + segmentId;
if (labels != null && labels.Count > 0)
{
    wr.LabelIds = new List<string>();
    wr.LabelIds.Add("Label_1");
    wr.LabelFilterAction = "include";
}

WatchResponse wrr = gs.Users.Watch(wr, emailAccount).Execute();
return "HistoryId " + wrr.HistoryId.ToString();

}

手表注册成功.问题是我收到有关Gmail更改的推送通知,而不仅仅是标签下的推送通知.

The watch registers OK. The issue is that I get push notifications for any Gmail change not just those under the label.

是否支持自定义标签?

推荐答案

我注意到了同样的问题,但后来发现这是由于API的工作方式所致.您可以通过LabelIds过滤电子邮件,但是只有将电子邮件直接过滤到选定的自定义标签时,您才会收到通知.我猜想它的设计,而不是API中的缺陷.

I noticed the same issue but later on found out that its because of the way API works. You can filter the emails via LabelIds but you will receive notifications only if emails are directly being filtered to selected custom label. I guess its design rather than a flaw in the API.

要对此进行测试,请在Gmail中创建一个自定义过滤器,该过滤器会将您的自定义标签直接应用于一组电子邮件,并且您应该收到这些电子邮件的通知.

To test this, create a custom filter in Gmail which would directly apply your custom label to a set of emails and you should be receiving notifications for those emails.

编辑(2015年6月11日): 推送通知会向您发送HistoryID和用户的邮箱名称.作为响应,您的端点应使用要监视更改的HistoryID和LabelId调用userhistory.list().

Edited (June 11, 2015): Push notification send you HistoryID and user's mailbox name. In response your endpoint should call userhistory.list() with HistoryID and LabelId you want to monitor for changes.

$opt_param = array();
$opt_param['startHistoryId'] = $historyID;
$opt_param['labelId'] = $labelID;
$opt_param['fields'] = 'nextPageToken,historyId,history/messagesAdded';

$service->users_history->listUsersHistory($userID, $opt_param);

上面是一个PHP代码段,用于使用historyID和labelID过滤历史记录列表.

Above is a PHP code snippet to filter the history list with historyID and labelID.

这篇关于Gmail API Watch未按标签过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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