我正在尝试删除消息标签。我能够成功阅读邮件,但是当我尝试修改邮件标签时出现问题
An error occurred: Google.Apis.Requests.RequestError Insufficient Permission [403] Errors Message[Insufficient Permission] Location[ - ] Reason[insufficientPermis sions] Domain[global]
我不得不尝试从 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修改消息中未读标签
ModifyMessageRequest mods = new ModifyMessageRequest();
mods.AddLabelIds = null;
mods.RemoveLabelIds = new List<string> { "UNREAD" });
service.Users.Messages.Modify(mods, userId, messageId).Execute();
最佳答案
你需要修复你的范围或者添加
https://www.googleapis.com/auth/gmail.labels Create, read, update, and delete labels only.
或者只是请求
https://mail.google.com/ Full access to the account, including permanent deletion of threads and messages. This scope should only be requested if your application needs to immediately and permanently delete threads and messages, bypassing Trash; all other actions can be performed with less permissive scopes.
removelablesids 还请求一个标签 ID
removeLabelIds[] A list IDs of labels to remove from this message.
我不认为 new List { "UNREAD"}); 会返回标签 ID。尝试做 lables.list找到标签和 ID
关于c# - 当我在 c# 中使用 gmail API 修改消息标签时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32834455/