Google Drive SDK (PHP) Children: list : the list is empty


I use this php function taken from the documentation

 * 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);

And i have 2 files in this folder, one is a picture and the other is folder but the $children var doesn't contain any item :

ChildList Object
    [nextPageToken] => 
    [kind] => drive#childList
    [__itemsType:protected] => ChildReference
    [__itemsDataType:protected] => array
    [items] => Array

    [nextLink] => 
    [etag] => "WtRjAPZWbDA7_fkFjc5ojsEvE7I/lmSsH-kN3I4LpwShGKUKAM7cxbI"
    [selfLink] =>

I also checked the folderId and is the good one, so not problem there.

My folder : Folder

And i don't have any error message


If you want to be able to list files, the only option is to use the broader scope: Please be aware that we do not recommend using this scope if listing files is not needed. by Alain

This video can help you solving your question :)
By: admin