getting 403 error when updating label with gmail api

-1

I am updating the label of a message. I get a 403 error as you can see below.

 if (!emailInfoResponse.LabelIds.Contains(SEND4PROCESSING))
                    {
                        Console.WriteLine("PROCESS ALERT  " + subject);
                        ModifyMessageRequest mods = new ModifyMessageRequest();
                        List<String> labelsToAdd = new List<String>()
                        {
                            SEND4PROCESSING
                        };
                        mods.AddLabelIds = labelsToAdd;
                        //  mods.RemoveLabelIds = labelsToRemove;
                        service.Users.Messages.Modify(mods, myemail, message.Id).Execute();


                    }

full code @ full code here and exception @ line 134

    Google.GoogleApiException
  HResult=0x80131500
  Message=Google.Apis.Requests.RequestError
Insufficient Permission [403]
Errors [
    Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global]
]
  Source=Google.Apis
  StackTrace:
   at Google.Apis.Requests.ClientServiceRequest`1.<ParseResponse>d__31.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Google.Apis.Requests.ClientServiceRequest`1.Execute()
   at IBTrading.GmailQuickstart..ctor() in C:\Users \Documents\Visual Studio 2019\Projects\IBTrading\GmailQuickstart.cs:line 134
   at IBTrading.Program.Main(String[] args) in C:\Users \Documents\Visual Studio 2019\Projects\IBTrading\Program.cs:line 14

i remembed to setup the update permission as you can see in the screenshot below.enter image description here

c#
gmail-api
asked on Stack Overflow Feb 9, 2020 by junkone • edited Feb 9, 2020 by junkone

1 Answer

0

Sounds like a problem with scopes

Line 22 in your code is

static string[] Scopes = { GmailService.Scope.MailGoogleCom };

The documentation for Users.messages: modify specifies:

This request requires authorization with at least one of the following scopes:

Scope

https://mail.google.com/

https://www.googleapis.com/auth/gmail.modify

Also be aware that after you changed the scopes from

GmailService.Scope.GmailReadonly

you need to delete you previous credentials / token file.

answered on Stack Overflow Feb 10, 2020 by ziganotschka

User contributions licensed under CC BY-SA 3.0