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

Question!

https://developers.google.com/drive/v2/reference/children/list

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] => https://www.googleapis.com/drive/v2/files/0B--Zn-zouTFrRURaNWp5VDN5LTA/children
)

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



Answers

If you want to be able to list files, the only option is to use the broader scope: https://www.googleapis.com/auth/drive. 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