当前位置: 首页 > 编程语言 > C#

GoogleAPI:Gmail服务推送通知(观察)-未经授权的用户执行此操作分享

时间:2023-04-10 14:26:10 C#

GoogleAPI:Gmail服务推送通知(观察)-未经授权的用户执行此操作我想在邮箱上调用watch().我设置了一个服务Iam帐户并创建了一个主题和订阅。我为我的服务帐户授予了对我的主题和订阅的完全(所有者)权限。但是在watch()上调用execute时,出现错误:Google.Apis.Requests.RequestError向CloudPubSubprojects/projectid/topics/topicname发送测试消息时出错:用户无权执行此操作。[403]错误[消息[向CloudPubSub项目/projectid/topics/topicname发送测试消息时出错:用户无权执行此操作。]Location[-]Reason[forbidden]Domain[global]]这是我使用的代码设置服务:credential=newX509Certificate2("file.p12"),"password",X509KeyStorageFlags.Exportable);varservice=newGmailService(newBaseClientService.Initializer(){HttpClientInitializer=credential,ApplicationName=applicationame,});WatchRequestbody=newWatchRequest(){TopicName="projects/projectid/topics/topicname",LabelIds=new[]{"INBOX"}stringuserId="me";UsersResource.WatchRequestwatchRequest=service.Users.Watch(body,userId);WatchResponse测试=watchRequest.Execute();我的服务帐户可以访问所有范围:https://mail.google.com/https://www。googleapis.com/auth/gmail.modifyhttps://www.googleapis.com/auth/gmail.readonlyhttps://www.googleapis.com/auth/gmail.metadata我在这里遗漏了什么吗?编辑添加以下范围,仍然没有成功:https://www.googleapis.com/auth/pubsub:https://www.googleapis.com/auth/pubsub编辑添加以下内容也没有成功:https://www.googleapis.com/auth/cloud-platform:https://www.googleapis.com/auth/cloud-platform我没有向gmail用于发布主题更新的服务帐户发布/订阅权限(TopicName):serviceAccount:gmail-api-push@system.gserviceaccount.com我在控制台给了这个账户权限你需要记住服务账户不是你。服务帐户是一个虚拟用户,它的googledrive帐户是一个googlecalendar帐户,可能还有更多。但它没有Gmail帐户。服务帐户是预授权的。您需要授予服务帐户访问权限以读取用户电子邮件。userId需要是您要访问其电子邮件的用户的ID。“我”将不起作用,因为服务器帐户没有没有电子邮件可读的Gmail帐户。只需要范围:https://www.googleapis.com/auth/gmail.modifyhttps://www.googleapis.com/auth/pubsub在CloudPub/SubDeveloperConsole中,您需要授予serviceAccount发布权限:gmail-api-push@system.gserviceaccount.com以上是C#学习教程:GoogleAPI:GmailServicePushNotification(观察)-未经授权的用户执行此操作所有内容分享,如果对大家有用,需要了解更多C#学习教程,希望大家多多关注—本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: