GmailService create Watch() getting User not authorized erro

本文关键字:User not authorized erro getting create Watch GmailService | 更新日期: 2023-09-27 18:25:19

此代码snniped:

  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项目/push-notifications-ver3/topics/mytopic发送测试消息时出错:用户未被授权执行此操作。[403]

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

GmailService create Watch() getting User not authorized erro

您是否完成了给定用户的OAuth过程?此外,您是否将方法AuthorizeAsync()中的单词"user"替换为经过身份验证的用户?如果是,则尝试使用新的客户端机密文件执行此操作,并检查变量作用域中是否存在PubSub作用域。

我面临着一个类似的问题,事实证明这就是其中之一。可能对你也有用。