title: Received error "Not Authorized to access this resource/api" when trying to use Google Directory API and Service Account Authentication
body: <p>I'm really struggling with trying to use Service Account authentication to use the Google Directory API (Admin SDK). </p>
  
  <p>Using client based three legged OAuth this works (tested here - <a href="https://developers.google.com/admin-sdk/directory/v1/reference/members/insert" rel="noreferrer">https://developers.google.com/admin-sdk/directory/v1/reference/members/insert</a>) but there's a problem with the permission delegation to the service account I am using. Under the Google Apps administration, I enabled using APIs and added the service account to the list of allowed OAuth clients as instructed.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>import httplib2
  import sys
  
  from apiclient.discovery import build
  from oauth2client.client import SignedJwtAssertionCredentials
  
  credentials = SignedJwtAssertionCredentials(
      '&lt;KEY&gt;@developer.gserviceaccount.com',
      '&lt;KEY DATA&gt;',
      scope='https://www.googleapis.com/auth/apps.groups.settings https://www.googleapis.com/auth/admin.directory.group https://www.googleapis.com/auth/admin.directory.group.member'
  )
  http = httplib2.Http()
  http = credentials.authorize(http)
  
  service = build("admin", "directory_v1", http=http)
  groups = service.groups()
  g = groups.get(groupKey="&lt;GROUP NAME&gt;").execute()
  </code></pre>
  
  <p>Eventually, I get the following error:</p>
  
  <pre><code>apiclient.errors.HttpError: &lt;HttpError 403 when requesting https://www.googleapis.com/admin/directory/v1/groups/&lt;GROUP NAME&gt;?alt=json returned "Not Authorized to access this resource/api"&gt;
  </code></pre>
  
  <p>I tried using the following API as well:</p>
  
  <pre><code>service = build("groupssettings", "v1", http=http)
  </code></pre>
  
  <p>But this returns an error as well - "Backend Error".</p>