google 驱动器 file.list 查询 returns 子文件夹 ID 为 false - php
google drive file.list query returns false for sub-folder ID - php
我可以使用以下函数列出位于 google 驱动器根目录中的文件夹中的项目。但是当我尝试列出位于父文件夹内的子文件夹中的项目时(父文件夹位于 google 驱动器的根目录中)
[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 驱动器的文件的函数:
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;
}
我可以知道如何列出子文件夹中的文件吗?
谢谢,
你需要做两件事
- 找出超级父文件夹中的哪些文件是子文件夹
您可以使用修改后的查询来完成:
$query2 = "'$superParentId' in parents and trashed = false and mimeType='application/vnd.google-apps.folder'";
...
- 循环列出这些子文件夹中包含的文件
...
$query3 = "'$subFolderId' in parents and trashed = false";
...
我可以使用以下函数列出位于 google 驱动器根目录中的文件夹中的项目。但是当我尝试列出位于父文件夹内的子文件夹中的项目时(父文件夹位于 google 驱动器的根目录中)
[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 驱动器的文件的函数:
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; }
我可以知道如何列出子文件夹中的文件吗?
谢谢,
你需要做两件事
- 找出超级父文件夹中的哪些文件是子文件夹 您可以使用修改后的查询来完成:
$query2 = "'$superParentId' in parents and trashed = false and mimeType='application/vnd.google-apps.folder'";
...
- 循环列出这些子文件夹中包含的文件
...
$query3 = "'$subFolderId' in parents and trashed = false";
...