As a super admin I tried to list the labels of a test user using the following codes take from this link but no success:https://developers.google.com/apps-script/advanced/gmail
function listLabelInfo() {
var response =
Gmail.Users.Labels.list('testuser@domain.com');
for (var i = 0; i < response.labels.length; i++) {
var label = response.labels[i];
Logger.log(JSON.stringify(label));
}
}
The error I get is this Delegation denied for myaccount@domain.com (line 2, file "Code")
.
Per instructions on the page, I did the following:
- Turned on Gmail API by going to Resources > Advanced Google services....
- Enabled Gmail API from the API Console of this project by going to Resource > Cloud Platform Project and then click on the My Project Name - project-id-0123456789012345678
- Created a Service account and checked the box for Enabled G
Suite Domain-Wide Delegation
On the Manage API Client Access console of the domain, entered the scope
https://www.googleapis.com/auth/gmail.labels
against the Client ID for the Service Account created in step#3 above.
I'm still getting the same error. If I use 'me
instead of 'testuser@domain.com'
, it shows all my labels.
What am I missing here?
Any help is greatly appreciated.