dream12001 2015-03-19 16:51
浏览 66

调用POST时出错https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart:(401)需要登录

I want to upload a file to google drive for that i have used following code and google drive sdk but i am getting following errors,Error calling POST https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart: (401) Login Required. I do not have much knowledge about integration of google drive sdk with php. Please help to solve it.

<?php

    include_once 'google-api-php-client-master/src/Google/Client.php';
    include_once 'google-api-php-client-master/src/Google/Service/Drive.php';
    include_once 'google-api-php-client-master/src/Google/Service/Oauth2.php';

    $client = new Google_Client();

    $client->setScopes(array('https://www.googleapis.com/auth/drive.file'));
    $client->setClientId('------');
    $client->setClientSecret('---------------');
    $client->setRedirectUri('https://www.example.com/oauth2callback');


    $service = new Google_Service_Drive($client);

    $data = file_get_contents("a.jpg");

    // create and upload a new Google Drive file, including the data
    try
    {
    //Insert a file
    $file = new Google_Service_Drive_DriveFile($client);

    $file->setTitle(uniqid().'.jpg');
    $file->setMimeType('image/jpeg');

    $createdFile = $service->files->insert($file, array('data' => $data,'mimeType' => 'image/jpeg','uploadType' => 'media',));
    }
    catch (Exception $e)
    {
        print $e->getMessage();
    }

    ?>
  • 写回答

1条回答 默认 最新

  • dongteng0748 2015-03-19 22:16
    关注

    You have to set up a new project under Google Developers Console. You can read more about the process, as well as a sample project, here: https://developers.google.com/drive/web/examples/php

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题