title: Google Drive api setting folder parents
body: <p>I have been trying to use google api to create first a root folder and then subfolders inside that root folder.  However the results have been less than encouraging.  Here is the code to create folders:</p>
  
  <pre><code>public function createFolder($name, $parents = array())
      {    
          /** @var $client \Google_Client */
          $client = $this-&gt;client;
          /** @var $service \Google_Service_Drive */
          $service = $this-&gt;service;
  
          if (is_null($service)) {
              throw new Exception("Invalid google api service");
          }
  
          if (!$client instanceof \Google_Client) {
              throw new Exception("Invalid google api client");
          }
  
          if (!isset($_SESSION['access_token'])) {
              throw new Exception("No access token found");
          }
  
          if (!$client-&gt;getAccessToken()) {
              throw new Exception("Could not find access token in client");
          }
  
          $folder = new \Google_Service_Drive_DriveFile();
          $folder-&gt;setTitle($name);
          $folder-&gt;setMimeType('application/vnd.google-apps.folder');
  
          if (!empty($parents)) {
              echo "Setting parents of $name to: " . implode(',', $parents);
              $folder-&gt;setParents($parents);
          } else {
              echo "\n No parent ids found \n";
          }
  
  
          echo "\n Creating new folder: {$name} \n";
  
          $output = $service-&gt;files-&gt;insert($folder, array(
              'mimeType' =&gt; 'application/vnd.google-apps.folder',
          ));
  
          return $output;
  
      }
  </code></pre>
  
  <p>Yet whenever I run this script the parents are not set.  Instead the subfolders are in a the drive alongside the parent folder.</p>
  
  <p>Also I tried to set the parent flags manually like so:</p>
  
  <pre><code>public function insertFileToFolder($childId, $parentId)
      {
          if (empty($childId) || empty($parentId)) {
              throw new Exception("Invalid parameter");
          }
  
          $service = $this-&gt;getService();
  
          try {
  
              echo "\n Trying to set subfolders \n";
              $parentReference = new \Google_Service_Drive_ParentReference();
              $parentReference-&gt;setId($parentId);
  
              return $service-&gt;parents-&gt;insert($childId, $parentReference);
  
          } catch (Exception $ex) {
              echo $ex-&gt;getMessage();
          }
  
          return null;
      }
  </code></pre>
  
  <p>Which does work... kind of.  It doesn't "move" the subfolders to the parent but instead either copies them or creates some kind of symlink and the folders appear to be under the parent folder.</p>
  
  <p>Edit: I've confirmed that the insertFileToFolder does not copy the files but instead sets symlinks.  Deleting the folder from root also deletes it from parent folder.</p>
  
  <blockquote>
    <p>Simple question really: What am I missing?</p>
  </blockquote>