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并且是好的,所以没问题。
我的文件夹:
我没有任何错误消息
答案 0 :(得分:1)
如果您希望能够列出文件,唯一的选择是使用更广泛的范围:https://www.googleapis.com/auth/drive。请注意,如果不需要列出文件,我们不建议使用此范围。作者:Alain