我正在通过服务帐户使用 Google PHP 库,并尝试使用文档 ID 获取共享团队驱动器中文档的名称。服务帐户是共享云端硬盘上的内容管理器。下面的代码会导致代码 404,找不到文件。
$client = new \Google_Client();
$client->setApplicationName('Google API Test');
$client->setScopes([\Google_Service_Drive::DRIVE]);
$client->setAccessType('offline');
$client->setAuthConfig('credentials.json);
$service = new \Google_Service_Drive($client);
$files = $service->files->get('xxxxxxxxxxxxxxxxxxxxxxxxxxx');
echo "File Name: " . $file->getName();
PHP Fatal error: Uncaught Google\Service\Exception: {
"error": {
"code": 404,
"message": "File not found: xxxxxxxxxxxxxxxxxxxxxxxxxxx.",
"errors": [
{
"message": "File not found: xxxxxxxxxxxxxxxxxxxxxxxxxxx.",
"domain": "global",
"reason": "notFound",
"location": "fileId",
"locationType": "parameter"
}
]
}
}
由于文件位于共享驱动器中,因此需要在 get 函数中包含supportsAllDrives 查询参数。
$file = $service->files->get($file_id, ['supportsAllDrives' => true]);