【发布时间】: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