I am trying to read the gmail mail message, using gmail api, and after reading the mail, I am removing the message label, so that I don't need to process it again. I am able to read the mail successfully, but when I am trying to modify the message Label
(service.Users.Messages.Modify(mods, userId, messageId).Execute();
)
then I am getting the error message:
An error occurred: Google.Apis.Requests.RequestError
Insufficient Permission [403]
Errors [
Message[Insufficient Permission] Location[ - ] Reason[insufficientPermis
sions] Domain[global]>
].
I am not able to figure out, what may have gone wrong? Thanks in advance.
you need to add the priviliges to the scope variable and then to delete the file storedCredentials (C:\Users\Administrateur.credentials.. )
I had similar problems with a console application using a Service Account API key. After adding all the necessary Scopes, as mentioned by Tholle above, the application has to be updated with the necessary permissions in the Google admin console. To do this, make sure you go to Admin console and remove the current app and execute the program again to get a new token with new permissions with the updated scope.
Another way to accomplish the same is to do what Mohamed has mentioned above. That is to remove the JSON file from the "...User\[UserName]\.credetials\[apiCredentialName].json" folder. This will force the app to authenticate and get a new token. Hope this helps some one :-)
I solved this problem by changing the Scopes variable. I assume you started with the QuickStart template which allows ReadOnly access only. You can change the scope as below:
using Google.Apis.Gmail.v1.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace GmailQuickstart
{
class Program
{
// CHANGE YOUR SCOPE HERE AND DELETE YOUR CREDENTIALS.JSON FILE IN THE PROJECT.
static string[] Scopes = { GmailService.Scope.GmailReadonly, GmailService.Scope.GmailModify };
static string ApplicationName = "Gmail API .NET Quickstart";
Reminder: After you changed the scope and delete your credentials.json, please re-authenticate your access from the gmail api again.
Hope it works out for you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With