Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to grant gmail access to a service account

Sap
Bronze 1
Bronze 1

Both ChatGPT and Bard give the following instructions, however there are no roles related to Gmail. So has anything changed or is there another way?

When trying to use the service account currently, I get the following error:
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://gmail.googleapis.com/gmail/v1/users/me/profile?alt=json returned "Precondition check failed.". Details: "[{'message': 'Precondition check failed.', 'domain': 'global', 'reason': 'failedPrecondition'}]

To give the service account access to read Gmail emails, you need to grant it the Gmail API Viewer role. You can do this by following these steps:

  1. In the Google Cloud Platform Console, click the IAM & Admin tab.
  2. Click the Roles tab.
  3. In the search bar, enter Gmail API Viewer.
  4. Click the Gmail API Viewer role.


Solved Solved
3 13 35.4K
1 ACCEPTED SOLUTION

Sap
Bronze 1
Bronze 1

I have pretty much a guide on readme of one of scripts here: https://github.com/sapn1s/gmail-email-checker

You do not need gmail.modify permission if you just want to read the emails.

Just for running on server without gui, you need to open the auth URL on an actual browser anywhere and just paste the code, after that it would remember your session.

View solution in original post

13 REPLIES 13
Top Labels in this Space