title: PHP Google API Client Forms Service Credentials
body: <p>I'm trying to use the Google Forms API with the google/apiclient composer package while authenticating with a service account like so...</p>
  <pre><code>putenv('GOOGLE_APPLICATION_CREDENTIALS=' . storage_path('google-api-credentials' . DIRECTORY_SEPARATOR . 'service-account.json'));
  $client = new \Google_Client();
  $client-&gt;setScopes([
      \Google\Service\Drive::DRIVE,
      \Google\Service\Drive::DRIVE_FILE,
      \Google\Service\Drive::DRIVE,
      \Google\Service\Drive::DRIVE_READONLY,
      \Google\Service\Forms::FORMS_BODY,
      \Google\Service\Forms::FORMS_BODY_READONLY,
      \Google\Service\Forms::FORMS_RESPONSES_READONLY,
  ]);
  $client-&gt;useApplicationDefaultCredentials(true);
  $client-&gt;setIncludeGrantedScopes(true);
  $client-&gt;setAccessType('offline');
  
  $service = new \Google_Service_Forms($client);
  
  $service-&gt;forms-&gt;get('some valid form id')
              
  </code></pre>
  <p>I have used this same service account to successfully use the Google Drive API in a very similar manner in the same codebase.  My issue is that, for the Forms API, the client doesn't seem to be handling authentication automatically like it does when using the Drive API.  The response I get back from the API on the above <a href="https://developers.google.com/forms/api/reference/rest/v1/forms/get" rel="nofollow noreferrer">forms.get</a> request is the following:</p>
  <pre><code>  {
    &quot;error&quot;: {
      &quot;code&quot;: 401,
      &quot;message&quot;: &quot;Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.&quot;,
      &quot;errors&quot;: [
        {
          &quot;message&quot;: &quot;Login Required.&quot;,
          &quot;domain&quot;: &quot;global&quot;,
          &quot;reason&quot;: &quot;required&quot;,
          &quot;location&quot;: &quot;Authorization&quot;,
          &quot;locationType&quot;: &quot;header&quot;
        }
      ],
      &quot;status&quot;: &quot;UNAUTHENTICATED&quot;,
      &quot;details&quot;: [
        {
          &quot;@type&quot;: &quot;type.googleapis.com/google.rpc.ErrorInfo&quot;,
          &quot;reason&quot;: &quot;CREDENTIALS_MISSING&quot;,
          &quot;domain&quot;: &quot;googleapis.com&quot;,
          &quot;metadata&quot;: {
            &quot;method&quot;: &quot;google.apps.forms.v1.FormsService.GetForm&quot;,
            &quot;service&quot;: &quot;forms.googleapis.com&quot;
          }
        }
      ]
    }
  }
  </code></pre>
  <p>My composer.json file contains this entry:</p>
  <pre><code>&quot;extra&quot;: {     
      &quot;google/apiclient-services&quot;: [
          &quot;Calendar&quot;,
          &quot;Drive&quot;,
          &quot;Gmail&quot;,
          &quot;Directory&quot;,
          &quot;Forms&quot;
      ]
  },
  </code></pre>
  <p>The forms API is enabled for the workspace account that the service account is associated with.  How do I fix this issue?  Do I need to perform the OAuth steps myself for the forms API OR is this just a misleading error message and I'm missing some kind of permission?  If I'm possibly missing a permission, which ones should I check and where can I find them in the google developer console?</p>