【发布时间】:2020-01-28 14:41:57
【问题描述】:
我将Google Drive API client 用于Laravel,并尝试按查询过滤器列出文件夹。
$scope = Config::get('options.gdrive_scopes');
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . base_path() . DIRECTORY_SEPARATOR . 'gdrive_atdnj.json');
$user = Config::get('options.google_drive_user_name');
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->setApplicationName(Config::get('app.name'));
$client->setScopes($scope);
$client->setAccessType('offline');
$client->setSubject($user);
$service = new \Google_Service_Drive($client);
$files_to_be_uploaded = Storage::files('orders/' . $orderId);
$project_folder_filters = array(
'fields' => 'files(id)',
'q' => "name contains '" . $project_folder_name . "' and mimeType='application/vnd.google-apps.folder'",
'supportsAllDrives' => true,
'includeItemsFromAllDrives' => true,
);
$project_folder_results = $service->files;
$project_folder_results = $service->files->listFiles($project_folder_filters);
dd($project_folder_filters, count($project_folder_results->getFiles()));
作为回报,我只得到了一个 One returned in result set 出现在 Google Drive 上的文件夹,其中创建了 2 个具有相同名称的文件夹 2 folders with same name。觉得楼主不一样。 如何使用给定的查询字符串使用谷歌驱动器 API 找到所有文件夹?
【问题讨论】:
-
您只能看到您登录的用户有权尝试删除 supportAllDrives 和 includeItemsFromAllDrives
-
@DaImTo,当我删除上述字段时,我在结果中什么也看不到。此外,有没有办法列出用户无权访问同一驱动器的文件?或者我可以将所有文件的所有者更改为服务帐户的方法?
-
您无法列出您无权访问的内容。它需要访问才能查看文件。让文件的所有者直接与服务帐户共享文件,尽管网络界面像您与任何其他用户一样共享文件。
-
@DaImTo,我没有看到为网络界面中的文件夹启用了共享选项:(
-
右键文件夹去分享你只有拥有它才能分享
标签: php web-services laravel-5 permissions google-drive-api