执行Google_Service_Drive-> files-> listFiles时,FilePermissions不足

时间:2016-09-17 13:50:57

标签: google-api-php-client

我正在尝试使用此引用列出Google云端硬盘上的文件:https://developers.google.com/drive/v3/web/search-parameters

我的PHP代码:

<?php
error_reporting(E_ALL);
set_include_path('<path>'); 
require_once("./vendor/autoload.php");
echo "start";
$client = new Google_Client();
$client->setApplicationName("Documents Management");
$client->setDeveloperKey("<key>");
$service = new Google_Service_Drive($client);
$pageToken = null;
do {
  $response = $service->files->listFiles(array(
    'q' => "mimeType='image/jpeg'",
    'spaces' => 'drive',
    'pageToken' => $pageToken,
    'fields' => 'nextPageToken, files(id, name)',
  ));
  foreach ($response->files as $file) {
      printf("Found file: %s (%s)\n", $file->name, $file->id);
  }
} while ($pageToken != null);


echo "end";
?>

但是,我收到以下异常:

PHP Fatal error:  Uncaught exception 'Google_Service_Exception' with message
'{  
   "error": {
     "errors": [
       {
         "domain": "global",
         "reason": "**insufficientFilePermissions**",
         "message": "The user does not have sufficient permissions for this file."
       }
     ],
     "code":    403,
     "message": "The user does not have sufficient permissions for this file."
   }
}'

异常文档(https://developers.google.com/drive/v3/web/handle-errors)表示我正在尝试修改该文件,但我只是尝试列出现有文件。我做错了什么?

谢谢, 哔叽

0 个答案:

没有答案