仅当新邮件进入Gmail的收件箱时,才接收推送通知

时间:2019-02-24 08:26:41

标签: push-notification google-api gmail-api google-cloud-pubsub google-api-dotnet-client

我已成功接收official documentation之后的Gmail用户(模拟)的服务帐户推送通知。

但是在致电watch时,我希望仅在收到新消息时得到通知,而不是在发生任何更改时得到通知。 (例如:已读邮件,已删除邮件...)

我尝试按INBOXUNREAD进行过滤,但是即使消息被标记为已读,我也会收到通知。

我的代码:

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

0 个答案:

没有答案