Gmail API does not filter shortcut

I use Gmail Push Notifications with Google PubSub and have a special tag that I want to track for any changes. I use the following code to register the hours for a label (label identifier 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(); 

}

The clock is recorded in order. The problem is that I get push notifications for any Gmail changes, not just those under the tag.

Are custom tags supported?

+8
gmail api
source share
1 answer

I noticed the same problem, but later found out that it was due to how the API works. You can filter emails using LabelIds, but you will only receive notifications if emails are directly filtered by the selected custom label. I guess its design, not a flaw in the API.

To test this, create a custom filter in Gmail that directly applies your custom shortcut to a set of emails, and you should receive notifications for these emails.

Edited (June 11, 2015): A push notification sends you the HistoryID and the user's mailbox name. In response, your endpoint should call userhistory.list () with the HistoryID and LabelId that you want to track 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); 

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

0
source share

All Articles