dongzhuo6137 2016-02-18 15:37
浏览 75

Google Drive API v3 PHP:上传文件调用未定义的方法

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?

  • 写回答

1条回答 默认 最新

  • dtrovwl75780 2016-02-18 23:50
    关注

    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'
    ));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题