2012-08-16 63 views
1

我需要使用谷歌驅動器PHP API創建電子表格,我該怎麼做? 我已經有代碼把它總能獲得無文件,當我點擊它,這裏沒有數據是我的代碼:PHP谷歌驅動器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電子表格,請插入一個文件,其內容爲mimeType,設置爲application/vnd.google-apps.spreadsheet

+0

如何使用新庫創建電子表格? – 2012-08-16 17:35:37

+1

只需將文件的'mimeType'設置爲'application/vnd.google-apps.spreadsheet':這將在用戶的Google Drive中創建一個空的電子表格。 – Alain 2012-08-16 20:55:50

+0

Thx @Alain爲了您的努力,您所有的答案都是正確的,我如何才能將內容放入空白的電子表格中? – 2012-08-16 21:25:41

相關問題