【发布时间】:2017-07-26 13:00:22
【问题描述】:
我正在努力使用 Google API PHP 客户端库在团队云端硬盘中创建一个文件夹。
我正在使用服务帐户并冒充一个用户(我自己),该用户是团队云端硬盘的成员,并且可以列出云端硬盘的内容。但是,当我创建一个文件夹时,它总是在“我的云端硬盘”而不是指定的团队云端硬盘中创建它。
尝试 1
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope("https://www.googleapis.com/auth/drive");
$client->setSubject('user@mydomain.com');
$service = new Google_Service_Drive($client);
$folderId = '0AIuzzEYPQu9CUk9PVA';
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => 'New Test Folder',
'mimeType' => 'application/vnd.google-apps.folder',
'supportsAllDrives' => true,
'parents' => ['0AIuzzEYPQu9CUk9PVA']
));
尝试 2
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => 'New Test Folder',
'mimeType' => 'application/vnd.google-apps.folder',
'supportsAllDrives' => true,
'driveId' => '0AIuzzEYPQu9CUk9PVA'
));
更新尝试 3
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => 'Hello 123',
'supportsAllDrives' => true,
'mimeType' => 'application/vnd.google-apps.folder',
'parents' => ['0AIuzzEYPQu9CUk9PVA']
));
$file = $service->files->create($fileMetadata, array(
'fields' => 'id'));
printf("Folder ID: %s\n", $file->id);
尝试 3 给出此错误: 致命错误:未捕获的 Google_Service_Exception:{ “error”:{ “errors”:[ { “domain”:“global”、“reason”:“notFound”、“message”:“找不到文件:0AIuzzEYPQu9CUk9PVA。”、“locationType” :“参数”,“位置”:“fileId”}]
我已阅读有关团队云端硬盘和 API 的所有(有限)documentation 并了解团队云端硬盘中的文件夹/文件只能有一个父级(团队云端硬盘的 ID),因此我尝试了父级的变体作为数组和字符串。
文件夹创建正确,只是在错误的地方。
【问题讨论】:
标签: php google-api google-drive-api google-api-php-client