2012-08-16 8 views
1

Google 드라이브 PHP API를 사용하여 스프레드 시트를 만들어야합니다. 어떻게해야합니까?PHP google 드라이브 api 스프레드 시트 만들기

/** 
* Insert new file. 
* 
* @param apiDriveService $service Drive API service instance. 
* @param string $title Title of the file to insert, including the extension. 
* @param string $description Description of the file to insert. 
* @param string $parentId Parent folder's ID. 
* @param string $mimeType MIME type of the file to insert. 
* @param string $filename Filename of the file to insert. 
* @return DriveFile The file that was inserted. NULL is returned if an API error occurred. 
*/ 
function insertFile($service, $title, $description, $parentId, $mimeType, $data) { 
$file = new DriveFile(); 
$file->setTitle($title); 
$file->setDescription($description); 
$file->setMimeType($mimeType); 

// Set the parent folder. 
if ($parentId != null) { 
    $parentsCollectionData = new DriveFileParentsCollection(); 
    $parentsCollectionData->setId($parentId); 
    $file->setParentsCollection(array($parentsCollectionData)); 
} 

try { 

    $createdFile = $service->files->insert($file, array(
     'data' => $data, 
     'mimeType' => $mimeType, 
    )); 

    // Uncomment the following line to print the File ID 
    // print 'File ID: %s' % $createdFile->getId(); 

    print_r($createdFile); 
} catch (Exception $e) { 
    print "An error occurred: " . $e->getMessage(); 
} 
} 
if(isset($_POST['insertFile'])){ 
$service = new apiDriveService($client); 
insertFile($service,'Google Maps Mrakers.txt','ADD Google Map Mrakers To File',NULL,'text/plain',$_POST['data']); 
exit; 
} 

답변

3

당신이 오래된 버전을 사용하고 있기 때문에이 문제가 발생하는 : 난 이미 코드가 항상 제목 파일을 가져 넣어 가지고 내가 그것을 클릭하면 여기에 데이터가없는 것은 내 코드입니다 PHP 클라이언트 라이브러리. 클라이언트를 프로젝트 repository 트렁크에 동기화하십시오.

코드를 처음 작성한 이후로 클라이언트 라이브러리가 리팩터링되면 일부 코드를 다시 작성해야합니다. Google Drive SDK documentation에있는 reference guides은이 리팩터링을 반영하도록 업데이트되었습니다.

Google 스프레드 시트를 만들려면 mimeTypeapplication/vnd.google-apps.spreadsheet으로 설정된 콘텐츠가없는 파일을 삽입하십시오.

+0

새 라이브러리를 사용하여 스프레드 시트를 만드는 방법은 무엇입니까? –

+1

파일의 'mimeType'을 'application/vnd.google-apps.spreadsheet'로 설정하면 사용자의 Google 드라이브에 빈 스프레드 시트가 생성됩니다. – Alain

+0

Thx @Alain 귀하의 모든 노력에 대한 답변이 정확합니다. 어떻게 빈 스프레드 시트에 내용을 넣을 수 있습니까? –

관련 문제