0

I have this code from google:

function retrieveAllFiles($service) {
$result = array();
$pageToken = NULL;

do {
 try {
   $parameters = array();
   if ($pageToken) {
     $parameters['pageToken'] = $pageToken;
   }
   $files = $service->files->listFiles($parameters);

   $result = array_merge($result, $files->getItems());
   $pageToken = $files->getNextPageToken();
  } catch (Exception $e) {
   print "An error occurred: " . $e->getMessage();
   $pageToken = NULL;
  }
 } while ($pageToken);
return $result;
}

I know i can do this:

$files = retrieveAllFiles($service);
foreach($files as $file){
   $id = $file->getId();
   $title = $file->getTitle()
}

We can also fetch the parents of the file by:

foreach($files as $file){
   $parents = $file->getParents();
}

Is it possible to get the titles of the parent folders without calling another request? like:

foreach($files as $file){
   $parents = $file->getParents();
   foreach($parents as $parent){
     $parent_title = $parent->getTitle(); //NOT EXISTING
   }
}

I know that it throws an error but is there other alternative to achieve this requirement?

pinoyyid
  • 21,499
  • 14
  • 64
  • 115
FritzB
  • 335
  • 3
  • 14

1 Answers1

0

No it's not possible. Embedding the meta data of one file within another would make for an ugly API. The Drive API is a very clean REST API, which means that you'll need to make multiple requests.

I've edited your question slightly to clarify that a file can have more than one parent.

pinoyyid
  • 21,499
  • 14
  • 64
  • 115