I’m doing a little page that lists all files that are in google drive. In the first time I do the authentication and save the refresh token + user id and email and then I list all the files. To get the information I do this:
$result = array();
$pageToken = NULL;
do {
try {
$parameters = array();
if ($pageToken) {
$parameters['pageToken'] = $pageToken;
}
$files = $service->files->listFiles($parameters);
$list=$files->getItems();
$result = array_merge($result,$list);
$pageToken = $files->getNextPageToken();
} catch (Exception $e) {
echo "An error occurred: " . $e->getMessage();
$pageToken = NULL;
}
} while ($pageToken);
And it works, but if the user refresh the page, I have do refresh the access token (getting the refresh token from db) and then proceed to do the same as above. In this case that code gives me an error because this time I get an associative array when I do:
$files = $service->files->listFiles($parameters);
To make it work I need to change the code to:
$result = array();
$pageToken = NULL;
do {
try {
$parameters = array();
if ($pageToken) {
$parameters['pageToken'] = $pageToken;
}
$files = $service->files->listFiles($parameters);
$list=$files['items'];
$result = array_merge($result,$list);
$pageToken = $files['nextPageToken'];
} catch (Exception $e) {
echo "An error occurred: " . $e->getMessage();
$pageToken = NULL;
}
} while ($pageToken);
This shouldn’t happen but I have no idea what’s wrong.
From the relevant php source of the class, I guess I found what makes you trouble.
Look at
Google_DriveService.php:It checks if you want to work with objects, or not:
$this->useObjects().This method is defined in the super class,
Google_ServiceResource.php:This tells me, that when you configure your service, you will have to set
'use_object'totrue.