您無法將演示文稿上傳到Google幻燈片。您需要做的是使用Google文檔類型將文件導入Google雲端硬盤。看看reference documentation這是一個如何實現這個目標的例子。這裏是如何實現你所需要的例子。
PPT到谷歌幻燈片演示文稿:
$service = new Google_Service_Drive($client);
// CREATE A NEW FILE
$file = new Google_Service_Drive_DriveFile(array(
'name' => 'PPT Test Presentation',
'mimeType' => 'application/vnd.google-apps.presentation'
));
$ppt = file_get_contents("SamplePPT.ppt"); // read power point ppt file
//declare opts params
$optParams = array(
'uploadType' => 'multipart',
'data' => $ppt,
'mimeType' => 'application/vnd.ms-powerpoint'
);
//import pptx file as a Google Slide presentation
$createdFile = $service->files->create($file, $optParams);
//print google slides id
print "File id: ".$createdFile->id;
PPTX到谷歌幻燈片演示文稿:
$service = new Google_Service_Drive($client);
// CREATE A NEW FILE
$file = new Google_Service_Drive_DriveFile(array(
'name' => 'PPTX Test Presentation',
'mimeType' => 'application/vnd.google-apps.presentation'
));
$pptx = file_get_contents("SamplePPTX.pptx"); // read power point pptx file
//declare opts params
$optParams = array(
'uploadType' => 'multipart',
'data' => $ppt,
'mimeType' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
);
//import pptx file as a Google Slide presentation
$createdFile = $service->files->create($file, $optParams);
//print google slides id
print "File id: ".$createdFile->id;
PDF到谷歌文檔文件:(不可能谷歌幻燈片演示文稿)
$service = new Google_Service_Drive($client);
// CREATE A NEW FILE
$file = new Google_Service_Drive_DriveFile(array(
'name' => 'PDF Test Document',
'mimeType' => 'application/vnd.google-apps.document'
));
$pdf = file_get_contents("SamplePDF.pdf"); // read pdf file
//declare opts params
$optParams = array(
'uploadType' => 'multipart',
'data' => $pdf,
'mimeType' => 'application/pdf'
);
//import pdf file as a Google Document File
$createdFile = $service->files->create($file, $optParams);
//print google document id
print "File id: ".$createdFile->id;
每個代碼片段中唯一更改的內容是mimeType
。對於MIME類型的參考,您可以visit here和Google Mime類型的參考,您可以visit here。
Did'nt work! ;( –
哪一個沒有工作?pptx? – Morfinismo
是的。沒有與pptx一起工作。 –