I've followed the quickstart at https://developers.google.com/drive/v3/web/quickstart/php and everything works fine.
I can search for files, download files but I am not able to upload files.
I'm using this approach here: 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'
));
But I always get an error like this:
Fatal error: Uncaught Error:
Call to undefined method Google_Service_Drive_Files_Resource::insert()
What am I missing?
The insert method has changed to create:
https://developers.google.com/drive/v3/reference/files/create
Another pitfall: $file->setTitle does also not work (use setName).
The final code looks like this:
$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'
));