【问题标题】:Gmail API: Watch Inbox label OnlyGmail API:仅观看收件箱标签
【发布时间】:2018-03-06 07:46:27
【问题描述】:

我有下面的代码来查看邮箱。正如所见,在 lableIds 中,我只有一个标签 INBOX,因为我只想收听新消息。但是,当我运行它时,它每隔 30 秒左右就会收到不同消息 ID 的通知。然而收件箱中没有发生任何变化,没有添加/删除新项目。如何将手表主体设置为仅收听 INBOX 的传入消息?

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

【问题讨论】:

  • 在我看来您使用的是服务帐户。您是否按照 Google Identity Platform developers.google.com/identity/protocols/… 官方文档中的说明冒充用户?
  • @Morfinismo 我已经编辑了代码以突出显示我传入被模拟用户的 id 的位置。我确实授予了我的服务帐户域范围的权限。

标签: c# gmail-api google-cloud-pubsub


【解决方案1】:

Gmail 显然忽略了请求的过滤器数据。这看起来是 gmail 中的一个已知错误。结帐https://issuetracker.google.com/issues/37300052 以监控进度,尽管它似乎很安静。我建议填写错误报告,以便至少重复。

对于我的用例,我只寻找具有特定自定义标签的电子邮件。可以存储该用户的历史 ID(请参阅https://developers.google.com/gmail/api/v1/reference/users/history/list),并且由于这是一个时代,因此仅每隔 X 分钟左右调用一次 gmail api。这会减少您拨打 gmail 的电话次数,但并不完美。

【讨论】:

    猜你喜欢
    • 2014-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-29
    • 2015-12-02
    • 1970-01-01
    • 2017-09-02
    • 1970-01-01
    相关资源
    最近更新 更多