python-samples
python-samples copied to clipboard
Using service account with domain-wide delegation still causing error "Precondition check failed"
Summary
If using a service account with domain-wide authority delegation, run this python sample code with userId=me or any email address within the organization, it will return an error:
{'message': 'Precondition check failed.', 'domain': 'global', 'reason': 'failedPrecondition'}
Expected Behavior
Service account with correct scopes should be able to access any userIds
Actual Behavior
Service account with correct scopes always gets error
{'message': 'Precondition check failed.', 'domain': 'global', 'reason': 'failedPrecondition'}
Steps to Reproduce the Problem
Follow the instructions here https://developers.google.com/admin-sdk/directory/v1/guides/delegation#python
- Create the service account and credentials
- Delegate domain-wide authority to your service account
- Assign the correct scopes according to here https://developers.google.com/gmail/api/reference/rest/v1/users.settings.sendAs/list
- Run the code from here https://github.com/googleworkspace/python-samples/blob/master/gmail/snippet/settings%20snippets/update_signature.py
Specifications
- Python 3.7.3
- macOS Monterey Version 12.3.1