我已成功接收official documentation之后的Gmail用户(模拟)的服务帐户推送通知。
但是在致电watch
时,我希望仅在收到新消息时得到通知,而不是在发生任何更改时得到通知。 (例如:已读邮件,已删除邮件...)
我尝试按INBOX
和UNREAD
进行过滤,但是即使消息被标记为已读,我也会收到通知。
我的代码:
this._service.Users.Watch(new WatchRequest
{
TopicName = "projects/my-project-id/topics/gmail",
LabelFilterAction = "include",
//LabelIds = new [] { "UNREAD" }
LabelIds = new[] { "INBOX" }
}, "me").Execute();
是否只有在收到新消息时才能收到通知?
这是订阅代码:
var projectId = "my-project-id";
var topicId = "gmail";
var subscriptionId = "unread-gmail";
TopicName topicName = new TopicName(projectId, topicId);
SubscriptionName subscriptionName = new SubscriptionName(projectId, subscriptionId);
PublisherClient publisher = await PublisherClient.CreateAsync(topicName);
SubscriberClient subscriber = await SubscriberClient.CreateAsync(subscriptionName);
await subscriber.StartAsync((msg, cancellationToken) =>
{
Console.WriteLine($"Received message {msg.MessageId} published at {msg.PublishTime.ToDateTime()}");
Console.WriteLine($"Text: '{msg.Data.ToStringUtf8()}'");
return Task.FromResult(SubscriberClient.Reply.Ack);
});