I´m having a problem to read emails in a corporative Gmail account, specifically a Gsuite Gmail account.
I followed this steps already:
- Go to the Google API Console.
- Create a new Project.
- Create a new Service Account
- Get the private key in p12 format
- Allow G Suite Domain-Wide Delegation of Authority to the Service Account.
- Go to the Gsuite Admin Panel.
- Go to the Security Section
- Allow the Email Scope(Read/Write/Send) https://mail.google.com/ to the Service Account.
- I made the following code: (https://developers.google.com/admin-sdk/reports/v1/guides/delegation) using the private p12 key. Here is the code: https://gist.github.com/sebastianmorenoe/40c16c1bb3420b27917d2dc58eb385f0
Unfortunately I'm receiving this error: com.google.api.client.auth.oauth2.TokenResponseException: 401 Unauthorized
Thank you very much for any help that you can provide.
Greetings