我已经跟随了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()
我错过了什么?
答案 0 :(得分:3)
插入方法已更改为创建:
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'
));