gpt4 book ai didi

c# - GmailService create Watch() 获取用户未授权错误

转载 作者:太空狗 更新时间:2023-10-29 22:00:24 25 4
gpt4 key购买 nike

这段代码被截断了:

  credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,//read from client secret.json file
Scopes,
"user",
CancellationToken.None).Result;

// Create Gmail API service.
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});

UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");
WatchRequest body = new WatchRequest()
{
TopicName = "projects/push-notifications-ver3/topics/mytopic",
LabelIds = new[] {"INBOX"}
string userId = "me";
UsersResource.WatchRequest watchRequest = service.Users.Watch(body, userId);
WatchResponse test = watchRequest.Execute();

获取错误:向 Cloud PubSub projects/push-notifications-ver3/topics/mytopic 发送测试消息时出错:用户无权执行此操作。 [403]

主题是通过订阅创建的,权限已授予当前用户作为主题所有者有什么建议为什么用户未被授权?

最佳答案

您是否为给定用户完成了 OAuth 流程?另外,您是否将 AuthorizeAsync() 方法中的“用户”一词替换为经过身份验证的用户?如果是,则尝试使用新的客户端 secret 文件执行此操作,并检查 PubSub Scope 是否存在于变量范围内。

我遇到了类似的问题,结果证明是这些问题之一。也可能对您有用。

关于c# - GmailService create Watch() 获取用户未授权错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34046598/

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