【问题标题】:issue when i modifying the Message Label using gmail API in c#当我在 c# 中使用 gmail API 修改消息标签时出现问题
【发布时间】:2015-12-26 08:55:28
【问题描述】:

我正在尝试删除消息标签。我能够成功阅读邮件,但是当我尝试修改邮件标签时出现问题

发生错误:Google.Apis.Requests.RequestError 权限不足 [403] 错误 消息[权限不足]位置[-]原因[权限不足] sions] 域[全局]

我不得不尝试从 json 创建一个服务,但它有同样的问题。 这是我的代码

var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                new ClientSecrets
                {
                    ClientId = clientId,
                    ClientSecret = clientSecret,
                },
                new[] { GmailService.Scope.MailGoogleCom, GmailService.Scope.GmailModify, GmailService.Scope.GmailCompose },//new[] { GmailService.Scope.GmailModify, GmailService.Scope.GmailCompose, GmailService.Scope.GmailReadonly },
                "user",
                CancellationToken.None).Result;

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

然后我调用 api 来修改消息中的标签 UNREAD

ModifyMessageRequest mods = new ModifyMessageRequest();
mods.AddLabelIds = null;
mods.RemoveLabelIds = new List<string> { "UNREAD" });
service.Users.Messages.Modify(mods, userId, messageId).Execute(); 

【问题讨论】:

    标签: c# .net google-api gmail-api google-api-dotnet-client


    【解决方案1】:

    你需要修复你的范围或者添加

    https://www.googleapis.com/auth/gmail.labels 仅创建、读取、更新和删除标签。

    或者只是请求

    https://mail.google.com/ 对帐户的完全访问权限,包括永久删除线程和消息。仅当您的应用程序需要绕过垃圾箱立即永久删除线程和消息时,才应请求此范围;所有其他操作都可以在许可范围较小的情况下执行。

    removelablesids 还请求一个标签 ID

    removeLabelIds[]  A list IDs of labels to remove from this message.
    

    我不认为 new List { "UNREAD" }); 会返回标签 ID。尝试使用lables.list 查找标签和id

    【讨论】:

    • 我尝试使用 GmailService.Scope.MailGoogleCom 和 GmailService.Scope.GmailLabels。但它不起作用
    • tks @DalmTo 这么多。我已经解决了我的问题。我转到此链接并删除权限并再次运行应用程序。然后它完美运行。 security.google.com/settings/security/permissions?pli=1
    猜你喜欢
    • 1970-01-01
    • 2023-03-13
    • 2016-04-22
    • 2019-07-24
    • 1970-01-01
    • 2023-03-19
    • 2019-04-18
    • 2020-04-25
    • 2020-10-29
    相关资源
    最近更新 更多