I'm trying to list files in Google Drive using Google's PHP API (https://developers.google.com/drive/v2/web/quickstart/php).
I've managed to obtain a scoped access token, but the sample code Google provides for listing files (https://developers.google.com/drive/v2/reference/files/list#response) is returning an error.
Here is my code:
$client = new Google_Client();
$client->setAuthConfigFile('/usr/share/nginx/google.json');
$client->setAccessToken($a4e->user->google_token); // access token scoped for DRIVE_READONLY
$drive_service = new Google_Service_Drive($client);
$files=retrieveAllFiles($drive_service);
var_dump($files);
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;
}
This returns the following error:
Fatal error: Call to undefined method Google_Service_Drive_FileList::getItems() in /usr/share/nginx/html/tools/google/index.php on line 30
Does anyone know what I'm doing wrong?
Many thanks in advance.