使用php在多个文件夹中的Google API查询文件 [英] Google API query files in multiple folders with php
问题描述
我正在尝试使用多个文件夹ID查询Google驱动器.
I am trying to query the google drive using multiple folder ids.
这是我的查询
$optParams = array(
'pageSize' => 1000
,'fields' => 'nextPageToken, files(contentHints/thumbnail,fileExtension,iconLink,id,name,size,thumbnailLink,webContentLink,webViewLink,mimeType,parents, kind, trashed, owners, modifiedTime)'
,[q] => "trashed=false and ('folder-id-1' in parents or 'folder-id-2' in parents or 'folder-id-3' in parents or 'folder-id-4' in parents or 'folder-id-5' in parents)"
);
$service = new \Google_Service_Drive($this->GoogleClient);
$results = $service->files->listFiles($optParams);
但是它仅返回前2个文件夹中的文件
But it is only returning files from the first 2 folders
编辑有关我的查询和返回结果的更多详细信息.文件夹ID已被清除.
Edit with more details about my query and the results returned. Folder Ids have been anominised.
$fldrs = [];
$fldrs[] = "folder-id-1"; // Toolkit 3 folders (Shared with me)
$fldrs[] = "folder-id-2"; // Untitled folder 1 file (mine)
$fldrs[] = "folder-id-3"; // Logos 14 files (not mine)
$fldrs[] = "folder-id-4"; // Posters (8 files - not mine)
$fldrs[] = "folder-id-5"; // Promo Assets (11 files not mine)
$q = "trashed=false and (";
$MaxFolders = 5;
for ($i=0;$i<$MaxFolders;$i++)
{
if ($i > 0) $q .= " or ";
$q .= "'{$fldrs[$i]}' in parents";
}
$q .= ")";
$optParams = array(
'pageSize' => 1000
,'fields' => 'nextPageToken, files(contentHints/thumbnail,fileExtension,iconLink,id,name,size,thumbnailLink,webContentLink,webViewLink,mimeType,parents, kind, trashed, owners, modifiedTime, driveId)'
,q => $q
);
$service = new \Google_Service_Drive($this->GoogleClient);
$results = $service->files->listFiles($optParams);
------
$ optParams(来自调试)
The $optParams (from debug)
array(3) (
[pageSize] => (int) 1000
[fields] => (string) nextPageToken, files(contentHints/thumbnail,fileExtension,iconLink,id,name,size,thumbnailLink,webContentLink,webViewLink,mimeType,parents, kind, trashed, owners, modifiedTime, driveId)
[q] => (string) trashed=false and ('folder-id-1' in parents or 'folder-id-2' in parents or 'folder-id-3' in parents or 'folder-id-4' in parents or 'folder-id-5' in parents)
)
这仅返回5个文件(文件夹3和4,以及3个文件:文件夹2中的1个文件,文件夹3中的1个文件,文件夹5中的1个文件)
This only returns 5 files (folders 3 and 4, and 3 files : 1 file from folder 2, 1 file from folder 3, 1 file from folder 5)
如果我只完成第一个文件夹,我将返回3个文件夹. 如果我有2个文件夹,我会得到2个文件夹和1个文件 如果我做3个文件夹,我会得到2个文件夹和2个文件 如果我有4个文件夹,我会得到2个文件夹和2个文件(与做3个文件夹相同)
If I work through and just do the 1st folder, I get 3 folders returned. If I do 2 folders, I get 2 folders and 1 file If I do 3 folders, I get 2 folders and 2 files If I fo 4 folders, I get 2 folders and 2 files (same as doing 3 folders)
如果我只选择文件夹3(徽标),那么我将获得全部14个文件.
If I pick to do just folder 3 (logos) I get all 14 files.
大多数文件不是我自己的.他们与我分享.
Most files are not my own. they are shared with me.
推荐答案
该参数不是数组.试试这个.
The parameter isnt an array. Try this.
$optParams = array(
'pageSize' => 1000
,'fields' => 'nextPageToken, files(contentHints/thumbnail,fileExtension,iconLink,id,name,size,thumbnailLink,webContentLink,webViewLink,mimeType,parents, kind, trashed, owners, modifiedTime)'
,'q' => "trashed=false and ('folder-id-1' in parents or 'folder-id-2' in parents or 'folder-id-3' in parents or 'folder-id-4' in parents or 'folder-id-5' in parents)"
);
这篇关于使用php在多个文件夹中的Google API查询文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!