title: Gmail API domain-wide delegation
body: <p>I am using Gmail API and I am trying to fetch emails from all users under company. But when I run code such as:</p>
  
  <pre><code>function runAPI(auth) {
    var gmail = google.gmail('v1');
    gmail.users.threads.list({auth: auth, userId: '108800016305523828361'},'',function(err, response){
      if (err) {
        console.log("The API returned an error: " + err);
        return;
      }
      var threads = response.threads;
      console.log(threads);
    })
  }
  </code></pre>
  
  <p>I get error:</p>
  
  <blockquote>
    <p>The API returned an error: Error: Delegation denied for xxxx@xxxxx.com</p>
  </blockquote>
  
  <p>In admin console I did this:</p>
  
  <p><a href="https://i.stack.imgur.com/sCpjZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sCpjZ.png" alt="enter image description here"></a></p>
  
  <p>As client name I used id from the <code>client_secret.json</code> file. And for scope, I gave it all permissions. </p>
  
  <p>How do I properly setup domain wide delegation for Gmail API ?</p>