title: Google Api Service Account Authorization
body: <p>This is my serivice.php file :</p>
  
  <pre><code>putenv('GOOGLE_APPLICATION_CREDENTIALS=service-account.json');
  $client = new Google_Client();
  $client-&gt;useApplicationDefaultCredentials();
  
  $client-&gt;setSubject('user@mydomain.com');
  
  $client-&gt;setScopes('https://www.googleapis.com/auth/drive.file');
  
  $service = new Google_Service_Drive($client);
  //Create a new drive file
  $file = new Google_Service_Drive_DriveFile();
  
  $file-&gt;setName('example');
  $file-&gt;setMimeType('application/vnd.google-apps.file');
  $data = file_get_contents('exapmle.txt');
    //Upload the file to google docs
  $createdFile = $service-&gt;files-&gt;create($file, array(
          'data' =&gt; $data,
          'mimeType' =&gt; $mimeType,
          'uploadType' =&gt; 'multipart'
        ));
  </code></pre>
  
  <p>I have service-account.json file in same working directory.</p>
  
  <p>But i am getting this error :</p>
  
  <pre><code>PHP Fatal error:  Uncaught Google_Service_Exception: {
   "error": "unauthorized_client",
   "error_description": "Client is unauthorized to retrieve access tokens using this method."
  }
   in \vendor\google\apiclient\src\Google\Http\REST.php:118
  </code></pre>
  
  <p>I have Enabled G Suite Domain-wide Delegation also.</p>