gpt4 book ai didi

c# - 谷歌 API : Gmail Service Push Notification (Watch) - User not authorized to perform this action

转载 作者:太空宇宙 更新时间:2023-11-03 12:31:55 25 4
gpt4 key购买 nike

我正在尝试在邮箱上调用 watch()。我设置了一个服务 Iam 帐户,并创建了一个主题和订阅。我向我的服务帐户授予了对我的主题和订阅的完全(所有者)权利。但是在 watch() 上调用 execute 时,出现错误:

Google.Apis.Requests.RequestError Error sending test message to Cloud PubSub projects/projectid/topics/topicname : User not authorized to perform this action. [403] Errors [ Message[Error sending test message to Cloud PubSub projects/projectid/topics/topicname : User not authorized to perform this action.] Location[ - ] Reason[forbidden] Domain[global] ]

这是我用来设置服务的代码:

 credential = new X509Certificate2("file.p12"), "password", X509KeyStorageFlags.Exportable);
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();

我的服务帐户可以访问以下所有范围:

https://mail.google.com/
https://www.googleapis.com/auth/gmail.modify
https://www.googleapis.com/auth/gmail.readonly
https://www.googleapis.com/auth/gmail.metadata

我是不是漏掉了什么?

编辑

添加了以下范围,但仍然没有成功:https://www.googleapis.com/auth/pubsub

编辑还添加了以下内容但没有成功:https://www.googleapis.com/auth/cloud-platform

最佳答案

我没有授予 gmail 用于发布 Pub/Sub 更新的服务帐户发布主题 (TopicName) 的权限:serviceAccount:gmail-api-push@system.gserviceaccount.com我在控制台中授予了此帐户权限。

关于c# - 谷歌 API : Gmail Service Push Notification (Watch) - User not authorized to perform this action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42433125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com