I have created one poc using Gmail API which read all email and print on console. I have take refrence from
Best practice is to only request the permissions you need. So the code is asking for the GmailScopes.GMAIL_LABELS permission which will only give you access to see the lables
Now to read a users messages the
as you can see the label scope is not there. Thats because you need a higher level of permissions to access this data..
Solution:
Change the scope in your code to request one of the scopes needed for messgaes.list.
Then you need to reauthorize your application. YOu can do this in a few was.
- delete the file found in TOKENS_DIRECTORY_PATH
- change .authorize("user"); the text passed here to something else.
When you run your app again it should prompt you for authorization again.