https://developers.google.com/drive/v2/reference/children/list
我使用从文档中获取的这个 php 函数
/**
* Print files belonging to a folder.
*
* @param apiDriveService $service Drive API service instance.
* @param String $folderId ID of the folder to print files from.
*/
function printFilesInFolder($service, $folderId) {
$pageToken = NULL;
do {
try {
$parameters = array();
if ($pageToken) {
$parameters['pageToken'] = $pageToken;
}
$children = $service->children->listChildren($folderId, $parameters);
foreach ($children->getItems() as $child) {
print 'File Id: ' . $child->getId();
}
$pageToken = $children->getNextPageToken();
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
$pageToken = NULL;
}
} while ($pageToken);
}
我在这个文件夹中有 2 个文件,一个是图片,另一个是文件夹,但 $children var 不包含任何项目:
ChildList Object
(
[nextPageToken] =>
[kind] => drive#childList
[__itemsType:protected] => ChildReference
[__itemsDataType:protected] => array
[items] => Array
(
)
[nextLink] =>
[etag] => "WtRjAPZWbDA7_fkFjc5ojsEvE7I/lmSsH-kN3I4LpwShGKUKAM7cxbI"
[selfLink] => https://www.googleapis.com/drive/v2/files/0B--Zn-zouTFrRURaNWp5VDN5LTA/children
)
我还检查了 folderId 并且是好的,所以那里没有问题。
我的文件夹:
而且我没有任何错误信息