title: Google Apps Script to retrieve other users' Gmail labels
body: <p>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:<a href="https://developers.google.com/apps-script/advanced/gmail" rel="nofollow noreferrer">https://developers.google.com/apps-script/advanced/gmail</a></p>
  
  <pre><code>function listLabelInfo() {
    var response =
      Gmail.Users.Labels.list('testuser@domain.com');
    for (var i = 0; i &lt; response.labels.length; i++) {
      var label = response.labels[i];
      Logger.log(JSON.stringify(label));
    }
  }
  </code></pre>
  
  <p>The error I get is this <code>Delegation denied for myaccount@domain.com (line 2, file "Code")</code>.</p>
  
  <p>Per instructions on the page, I did the following:</p>
  
  <ol>
  <li>Turned on <strong>Gmail API</strong> by going to <strong>Resources > Advanced Google
  services....</strong></li>
  <li>Enabled <strong>Gmail API</strong> from the API Console of this project by going to <strong>Resource > Cloud Platform
  Project</strong> and then  click on the <strong>My Project Name -
  project-id-0123456789012345678</strong></li>
  <li>Created a <strong>Service account</strong> and checked the box for <strong>Enabled G
  Suite Domain-Wide Delegation</strong>
  On the <strong>Manage API Client Access</strong> console of the domain, entered the scope <code>https://www.googleapis.com/auth/gmail.labels</code> against the <strong>Client ID</strong> for the <strong>Service Account</strong> created in step#3 above.</li>
  </ol>
  
  <p>I'm still getting the same error. If I use <code>'me</code> instead of <code>'testuser@domain.com'</code>, it shows all my labels.</p>
  
  <p>What am I missing here?</p>
  
  <p>Any help is greatly appreciated.</p>