[英]How to get all folders & files based on Owner using PHP with Google Drive API
如何根据所有者获取所有文件和文件夹?
https://imgur.com/gallery/uf8nXOX
我试过这个查询,但它只是列出所有 sharedWithMe :
<?php
//fields can be use files(id, name, modifiedTime, mimeType, parents, trashed, permissions, webViewLink, webContentLink, exportLinks), nextPageToken
$client = new Google_Client();
$client->setApplicationName('Google Drive API PHP Quickstart');
$client->setAuthConfig('gdrive/json/'. $_SESSION['json'] . '.json');
$client->setScopes(Google_Service_Drive::DRIVE);
$client->setSubject($_SESSION['json_email']);
$client->setAccessType('offline');
$service = new Google_Service_Drive($GLOBALS['client']);
$parameters['pageSize'] = 250;
$parameters['q'] = "sharedWithMe and mimeType='application/vnd.google-apps.folder'";
//"mimeType='application/vnd.google-apps.folder' and 'root' in parents and trashed=false";
$parameters['fields'] = 'files(id, name,modifiedTime,owners), nextPageToken';
//'files(id, name, modifiedTime, mimeType, parents, trashed, permissions, webViewLink, webContentLink, exportLinks), nextPageToken';
$files = $service->files->listFiles($parameters);
foreach( $files as $k => $file ){
echo " <tr>
<td><large><i class='ti-folder'></i></large>
";
$forlinkowners = $file['owners'];
foreach ($forlinkowners as $pp => $getowner2){
echo "<a href='rmsystems.php?shared&&id=".$file['id']."&&foldername=".$file['name']."&&email=".$getowner2['emailAddress']."'>";
echo folder_from_rename($file['name']) . "  <span class='badge badge-primary'>link</span>";
echo "</a></td>
<td><i class='ti-crown'></i>  ".retrieve_name($getowner2['emailAddress']).
"</td>";
}
echo "</tr> ";
}
?>
我只想按所有者对它们进行分组。 有什么建议么? 我将如何在 PHP 中执行它还是应该在 google API 中查询它?
非常感谢!
您的请求使用的是 sharedWithMe 您应该使用“owners in”
"'test@example.org' in owners"
您不能搜索不在文件夹(父)中的文件,您只能搜索文件夹中的文件
'root' in parents
将返回'root' in parents
所有文件。 但是, 'root' not in parents
将失败,因为它无效。
我 100% 确定您所说的父键是什么意思。 如果您只想要某些目录中的文件,我建议您对每个想要的目录运行请求,而忽略不需要的目录。 这将意味着多个请求或只是获取所有内容并在本地对其进行排序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.