google drive file.list查询返回子文件夹ID-php的false

google drive file.list查询返回子文件夹ID-php的false,php,google-drive-api,google-oauth,google-api-php-client,Php,Google Drive Api,Google Oauth,Google Api Php Client,我可以使用以下功能列出位于google drive根目录下的文件夹中的项目。但当我尝试列出位于父文件夹内的子文件夹中的项目时,父文件夹位于google drive的根目录中 [PARENT FOLDER] //the 'sub folder' and 'other files' are getting listed └------[SUB FOLDER] //query is returned false when i try to put this folder ID as pa

我可以使用以下功能列出位于google drive根目录下的文件夹中的项目。但当我尝试列出位于父文件夹内的子文件夹中的项目时,父文件夹位于google drive的根目录中

[PARENT FOLDER] //the 'sub folder' and 'other files' are getting listed └------[SUB FOLDER] //query is returned false when i try to put this folder ID as parent | └--------[FILE LOCATED INSIDE SUB FOLDER] └------[OTHER FILES] 用于列出google drive中的文件的函数:

function listFilesFolders($client, $search, $subFolderId){ $service = new Google_Service_Drive($client); //ID of the folder located in root of google drive //works fine if i run the query with this ID $superParentId = '1Xky058b134vadgSOyD-ADFagaGAGAdgha'; //properly working query //$query = "'".$superParentId."' in parents and trashed = false"; //query that runs for the subfolder located inside the parent folder ($superParentId) $query = "'".$subFolderId."' in parents and trashed = false"; $optParams = array('q' => $query); // Returns the list of files and folders as object $results = $service->files->listFiles($optParams); // Return false if nothing is found if (count($results->getFiles()) == 0) { return false; } // Converting array to object $result = array(); foreach ($results->getFiles() as $file) { $result[$file->getId()] = $file->getName(); } return $result; } 我可以知道如何列出子文件夹中的文件吗


谢谢,

你需要做两件事

找出超级父文件夹中的哪些文件是子文件夹 您可以通过修改的查询执行此操作: 在循环中列出这些子文件夹中包含的文件
您的方法需要是递归的,并使用新的子文件夹调用自己。我陷入了选择父文件夹然后使用子文件夹ID递归运行查询的过程中。你能用一段代码来说明吗?你需要这样的列表文件文件夹$client,$search,$file->getId,但我建议先检查它是否是一个文件夹。检查文件类型,它会告诉您它是否是文件夹。很抱歉,have的唯一示例是C语言,我现在没有时间用php制作示例。您好,我是否需要运行$service->files->listFiles$optParams,在从具有“SuperParentID”的查询中抓取的每个循环中使用子文件夹ID?我可以在函数中获得子文件夹ID作为参数。。当O使用参数运行时。它返回false。确切地说,当您使用“SuperParentID”和mimeType='application/vnd.google apps.folder'运行查询时,您将获得一个可能包含多个子文件夹的数组。因此,您需要遍历这些子文件夹和每个子文件夹的列表文件。在用PHP实现它之前,我建议您尝试使用不同查询的API。嗨,我已经解决了这个问题。我正在使用scope drive.file。它只列出由我的应用程序创建的文件。子文件夹的内容直接从google drive上传。这就是为什么它没有在循环中列出。要使用的正确范围是使用驱动器范围。
$query2 = "'$superParentId' in parents and trashed = false and mimeType='application/vnd.google-apps.folder'";
... 
...
$query3 = "'$subFolderId' in parents and trashed = false";
...