I’m working on a Joomla extension that needs to display files from a specific Google Drive directory. The component should work as a background service without user authentication.
The problem is that my API calls always return zero items even though I know there are files in the drive. I’m wondering if my client setup is incorrect or if there’s an issue with how I configured the application in Google Console.
Here’s my current implementation:
// Configuration file contains all Google Console credentials
require_once(dirname(__FILE__) . '/drive/settings.php');
require_once(dirname(__FILE__) . '/drive/google-api/googleClient.php');
require_once(dirname(__FILE__) . '/drive/google-api/services/googleDriveService.php');
$googleClient = new googleClient();
$privateKey = file_get_contents(Settings::PRIVATE_KEY_PATH);
$googleClient->setClientId(Settings::APP_CLIENT_ID);
$googleClient->setUseObjects(true);
$googleClient->setAssertionCredentials(new googleAssertionCredentials(
Settings::SERVICE_EMAIL,
array('https://www.googleapis.com/auth/drive'), $privateKey)
);
$driveService = new googleDriveService($googleClient);
try {
$options = array();
$options['maxResults'] = $maxItems;
$fileList = $driveService->files->listFiles($options);
$documents = $fileList->getItems();
var_dump($documents);
$nextToken = $fileList->getNextPageToken();
} catch (googleServiceException $ex) {
echo "Service error: " . $ex->getCode() . "\n";
echo "Error details: " . $ex->getMessage() . "\n";
} catch (googleException $ex) {
echo "API error: (" . $ex->getCode() . ") " . $ex->getMessage() . "\n";
} catch (Exception $ex) {
echo "Failed to fetch files";
echo($ex->getMessage());
}
This is really frustrating and I can’t figure out what’s wrong. Any help would be appreciated.
Note: I used the official Google documentation for service account setup as my reference.