我已按照 https://developers.google.com/drive/v3/web/quickstart/php 上的快速入门进行操作一切正常。
我可以搜索文件、下载文件,但无法上传文件。
我在这里使用这种方法: https://developers.google.com/api-client-library/php/guide/media_upload
$file = new Google_Service_Drive_DriveFile();
$result = $service->files->insert($file, array(
'data' => file_get_contents("path/to/file"),
'mimeType' => 'application/octet-stream',
'uploadType' => 'media'
));
但我总是收到这样的错误:
Fatal error: Uncaught Error:
Call to undefined method Google_Service_Drive_Files_Resource::insert()
我错过了什么?
最佳答案
插入方法已更改为创建:
https://developers.google.com/drive/v3/reference/files/create
另一个陷阱:$file->setTitle 也不起作用(使用 setName)。
最终的代码如下所示:
$file = new Google_Service_Drive_DriveFile();
$file->setName($filename);
$result = $service->files->create($file, array(
'data' => file_get_contents("path/to/file"),
'mimeType' => 'application/octet-stream',
'uploadType' => 'media'
));
关于php - 谷歌云端硬盘 API v3 PHP : Upload a file Call to undefined method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35485788/