1
我使用谷歌驅動器sdk上傳文件,我想我可以創建PDF文件 - 所以我調整了代碼。因此,在我的代碼中,我生成HTML文本格式以用作要在Google Drive中創建的PDF的內容。使用谷歌驅動器創建PDF文件的錯誤sdk
這是我的代碼片段。
$subcontent = "<h1>Hello World</h1><p>some text here</p>";
$file = new Google_DriveFile();
....
$mkFile = $this->_service->files->insert($file, array('data' => $subcontent));
$createdFile = $fileupload->nextChunk($mkFile, $subcontent); // I got error on this line
$this->_service->files->trash($createdFile['id']);
...
,當我跑我得到了一個錯誤的代碼基於我把我上面的代碼註釋:
Catchable fatal error: Argument 1 passed to Google_MediaFileUpload::nextChunk() must be an instance of Google_HttpRequest, array given, called in /home/site/public_html/mywp/wp-content/plugins/mycustomplugin/functions.php on line 689 and defined in /home/site/public_html/mywp/wp-content/plugins/mycustomplugin/gdwpm-api/service/Google_MediaFileUpload.php on line 212
我不知道應該在nextChunk
在第二個參數的值,在原來的代碼是這樣的:
.....
$handle = fopen($path, "rb");
while (!$status && !feof($handle)) {
$max = false;
for ($i=1; $i<=$max_retries; $i++) {
$chunked = fread($handle, $chunkSize);
if ($chunked) {
$createdFile = $fileupload->nextChunk($mkFile, $chunked);
break;
}elseif($i == $max_retries){
$max = true;
}
}
.....
我的問題是,我該如何處理這個錯誤?以及如何通過調整此代碼成功地在谷歌驅動器中創建PDF文件?因爲我需要在我的文章中鏈接文件的創建文件ID。
在此先感謝...