3
votes

I am trying to removing the message label. I am able to read the mail successfully, but when I am trying to modify the message Label i have a problem

An error occurred: Google.Apis.Requests.RequestError Insufficient Permission [403] Errors Message[Insufficient Permission] Location[ - ] Reason[insufficientPermis sions] Domain[global]

i had to try to created a service from json but it have a same issue. and this is my code

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,
        });

and then i call api to modify label UNREAD in message

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

1 Answers

0
votes

You need to fix your scopes either add

https://www.googleapis.com/auth/gmail.labels Create, read, update, and delete labels only.

or just request

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.

Also removelablesids requests a label ID

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

I don't think new List { "UNREAD" }); is going to return the label id. try doing lables.list to find the labels and there ids