title: How to delete folder drive api
body: <p><strong>I am unable to delete a folder</strong> (created by another person) even if I try to change the rights, I have a console application and the current authenticated user can do the following :</p>
  
  <ol>
  <li>create folders/files </li>
  <li>move files</li>
  </ol>
  
  <p>Scopes:</p>
  
  <pre><code>'https://www.googleapis.com/auth/drive',
  'https://www.googleapis.com/auth/drive.file',
  'https://www.googleapis.com/auth/drive.appdata',
  'https://spreadsheets.google.com/feeds',
  </code></pre>
  
  <h2>Tries:</h2>
  
  <p>1.Set permissions to the current user</p>
  
  <pre><code>public function deleteFolder(\Google_Service_Drive_DriveFile $folder)
  {
      $permission = new \Google_Service_Drive_Permission();
      $permission-&gt;setRole( 'owner' );
      $permission-&gt;setType( 'user' );
      $permission-&gt;setEmailAddress('someId@developer.gserviceaccount.com');
      $permission = $this-&gt;googleDriveClient-&gt;permissions-&gt;create( $folder-&gt;getId(),$permission,array('transferOwnership'=&gt;true));
      $this-&gt;googleDriveClient-&gt;files-&gt;delete($folder-&gt;getId());
  }
  </code></pre>
  
  <p>Result:</p>
  
  <blockquote>
    <p>[Google_Service_Exception]          {<br>
    "error": {<br>
        "errors": [<br>
         {<br>
          "domain": "global",<br>
          "reason": "internalError",<br>
          "message": "Internal Error"<br>
         }<br>
        ],<br>
        "code": 500,<br>
        "message": "Internal Error"        }                                  }</p>
  </blockquote>
  
  <p>2.Set permission <strong>type</strong> to <strong>anyone</strong></p>
  
  <blockquote>
  <pre><code>public function deleteFolder(\Google_Service_Drive_DriveFile $folder)
  {
      $permission = new \Google_Service_Drive_Permission();
      $permission-&gt;setRole( 'owner' );
      $permission-&gt;setType( 'anyone' );
      $permission = $this-&gt;googleDriveClient-&gt;permissions-&gt;create( $folder-&gt;getId(),$permission,array('transferOwnership'=&gt;true));
      $this-&gt;googleDriveClient-&gt;files-&gt;delete($folder-&gt;getId());
  }
  </code></pre>
  </blockquote>
  
  <p>Result:</p>
  
  <blockquote>
    <p>[Google_Service_Exception]<br>
    {<br>
    "error": {                                                            </p>
  
  <pre><code>"errors": [                                                                
   {                                                                         
    "domain": "global",                                                      
    "reason": "insufficientFilePermissions",                                 
    "message": "The user does not have sufficient permissions for this file  ."                                                         
  
   }                                                                         
  ],                                                                         
  "code": 403,                                                               
  "message": "The user does not have sufficient permissions for this file."      }                                                         
  </code></pre>
    
    <p>}</p>
  </blockquote>
  
  <p>try 3: Impersonate the creator</p>
  
  <pre><code>$this-&gt;googleClient-&gt;setAccessType('offline');
  $this-&gt;googleClient-&gt;setSubject('x@domain.com');//if removed everything works 
  </code></pre>
  
  <blockquote>
    <p>[GuzzleHttp\Exception\ClientException]<br>
    Client error: <code>POST https://www.googleapis.com/oauth2/v4/token</code>
    resulted in      a <code>401 Unauthorized</code> response:<br>
    {<br>
    "error": "unauthorized_client",<br>
    "error_description": "Unauthorized client or scope in request.",<br>
    "error_uri": ""<br>
    }</p>
  </blockquote>
  
  <p>Am I missing something?</p>