我正在尝试从属于我们G Suite帐户的Google云端硬盘中检索图片。
我创建了一个服务帐户并授予它域范围的权限,我将json文件传递给我创建的客户端。我可以成功获取文件元数据但是当我尝试使用示例代码下载实际文件时,调用什么都不返回:
$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);
}
我在这里做错了吗?
TIA