I am trying to retrieve an image from a Google Drive that is part of our G Suite account.
I have created a service account and granted it domain-wide authority and I am passing the json file to the client that I create. I can successfully get the file metadata however when I try to download the actual file using the sample code, the call returns nothing:
$client = new Google_Client();
$client->setAuthConfig(getcwd() . '\credentials\API-Project-b1efa769fa8c.json');
$client->setApplicationName('API Project');
$client->setSubject('tdellett@georgesmusic.com');
$client->setScopes(SCOPES);
$fileURL = 'https://drive.google.com/file/d/1OwBr3dHakMYviIO9uCI-lkFkygU3pMB8/view?usp=sharing';
$URLParts = explode('/', $fileURL);
$find = array_search('d', $URLParts);
if ($find !== false) {
$fileId = $URLParts[$find + 1];
$service = new Google_Service_Drive($client);
$response = $service->files->get($fileId, array('supportsTeamDrives' => 'true'));
$fileName = $response->getName();
$mimeType = $response->getMimeType();
$contentLink = $response->getWebContentLink();
$response = $service->files->get($fileId, array('alt'=>'media','supportsTeamDrives' => 'true'));
$content = $response->getBody()->getContents();
file_put_contents($fileName, $content);
}
Am I doing something completely wrong here?
TIA