使用谷歌驱动器api时出现致命错误

时间:2012-09-29 16:01:22

标签: google-drive-api

我想从php文件中获取我的google docs文件,并编写以下代码:

require_once ("google/Google_Client.php");
require_once ("google/contrib/Google_DriveService.php");

$client=new Google_Client();
$client->setClientId('XXXX');
$client->setClientSecret('xxxx');
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$client->setScopes(array('https://www.googleapis.com/auth/drive'));
$service = new Google_DriveService($client);
$parameters=array();
$parameters['q'] = "title contains 'something'";
$children = $service->children->listChildren('root',$parameters);
var_dump($children);

但返回以下信息:

  

致命错误:未捕获的异常'Google_ServiceException',显示消息'错误调用GET https://www.googleapis.com/drive/v2/files/root/children?q=title%20contains%20%27something%27 :( 404)未找到'

1 个答案:

答案 0 :(得分:1)

您的应用程序未正确执行OAuth流程,请查看Google Drive SDK文档中的PHP快速入门示例,了解应如何实施该示例:

https://developers.google.com/drive/quickstart

一旦您的代码正确执行了OAuth流程,您就可以替换示例中的代码以上传文件以执行搜索。