2015-02-04 1 views
0

Google 어피를 사용하여 먼저 루트 폴더를 만든 다음 해당 루트 폴더 내에 하위 폴더를 만들려고했습니다. 그러나 결과는 격려보다 적습니다. 다음은 폴더를 생성하는 코드입니다.Google 드라이브 API 설정 폴더 부모

public function createFolder($name, $parents = array()) 
    {  
     /** @var $client \Google_Client */ 
     $client = $this->client; 
     /** @var $service \Google_Service_Drive */ 
     $service = $this->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->getAccessToken()) { 
      throw new Exception("Could not find access token in client"); 
     } 

     $folder = new \Google_Service_Drive_DriveFile(); 
     $folder->setTitle($name); 
     $folder->setMimeType('application/vnd.google-apps.folder'); 

     if (!empty($parents)) { 
      echo "Setting parents of $name to: " . implode(',', $parents); 
      $folder->setParents($parents); 
     } else { 
      echo "\n No parent ids found \n"; 
     } 


     echo "\n Creating new folder: {$name} \n"; 

     $output = $service->files->insert($folder, array(
      'mimeType' => 'application/vnd.google-apps.folder', 
     )); 

     return $output; 

    } 

그러나이 스크립트를 실행할 때마다 부모는 설정되지 않습니다. 대신 하위 폴더는 상위 폴더와 함께 드라이브에 있습니다.

또한 나는과 같이 수동으로 부모 플래그를 설정하려고 : 작업을 수행

public function insertFileToFolder($childId, $parentId) 
    { 
     if (empty($childId) || empty($parentId)) { 
      throw new Exception("Invalid parameter"); 
     } 

     $service = $this->getService(); 

     try { 

      echo "\n Trying to set subfolders \n"; 
      $parentReference = new \Google_Service_Drive_ParentReference(); 
      $parentReference->setId($parentId); 

      return $service->parents->insert($childId, $parentReference); 

     } catch (Exception $ex) { 
      echo $ex->getMessage(); 
     } 

     return null; 
    } 

... 가지. 하위 폴더를 상위 폴더로 "옮기지"않고 대신 복사하거나 일부 종류의 심볼릭 링크를 만들고 폴더가 상위 폴더 아래에있는 것처럼 보입니다.

편집 : insertFileToFolder가 파일을 복사하지 않고 대신 symlinks를 설정한다는 것을 확인했습니다. 루트에서 폴더를 삭제하면 상위 폴더에서도 삭제됩니다.

정말 간단한 질문입니다. 무엇이 누락 되었습니까? 함수에서

답변