0
我有下面的代碼來觀看郵箱。正如所見,在lableIds中,我只有一個標籤,INBOX,因爲我只想聽新消息。但是,當我運行它時,它會每隔30秒左右收到不同messageID的通知。然而,在INBOX中沒有發生任何變化,沒有添加/刪除新項目。如何將我的手錶機身設置爲僅收聽收到的消息的INBOX?Gmail API:觀看收件箱標籤只有
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的官方文檔https://developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority中的說明模仿用戶? – Morfinismo
@Morfinismo我編輯了代碼,以突出顯示我在被模擬的用戶的ID中傳遞的位置。我確實授予了我的服務帳戶在全域範圍內的權限。 – jpo