我想将文件上传到我的TeamDrive,但失败了。上传到我的驱动器工作。
我使用本地文件调用该功能,在我的TeamDrive中使用文件夹ID和Team Drive ID的数组。$服务A Google_service_drive对象和$客户端google_client
我使用选项supportSteamDrives。
如果我尝试ListFiles也不存在TeamDrives。
我如何在php中加速API?
此版本现在有效:
function uploadGD($local_file, $folderid = NULL, $teamdrive = NULL)
{
global $service;
global $client;
try {
// Call the API with the media upload, defer so it doesn't immediately return.
$client->setDefer(true);
//$request = $service->files->create($file);
$optParams = array(
'fields' => 'id',
'supportsTeamDrives' => true,
);
$request = $service->files->create(new Google_Service_Drive_DriveFile(array(
"name" => basename($local_file),
"teamDriveId" => $teamdrive,
"parents" => $folderid,
"mimeType" => mime_content_type($local_file))), $optParams);
// Create a media file upload to represent our upload process.
$media = new Google_Http_MediaFileUpload(
$client,
$request,
mime_content_type($local_file),
null,
true,
1 * 1024 * 1024
);
$media->setFileSize(filesize($local_file));
// Upload the various chunks. $status will be false until the process is
// complete.
$status = false;
$handle = fopen($local_file, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
// The final value of $status will be the data from the API for the object
// that has been uploaded.
$result = false;
if($status != false) {
$result = $status;
}
fclose($handle);
// Reset to the client to execute requests immediately in the future.
$client->setDefer(false);
return "google|" . $result["id"];
} catch (Exception $e) {
return "Fehler:".$e->getMessage();
}
}
错误消息显示:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "File not found: 0AHUD0ou-txfUUk9PVA.",
"locationType": "parameter",
"location": "fileId"
}
],
"code": 404,
"message": "File not found: 0AHUD0ou-txfUUk9PVA."
}
}
"找不到文件:0ahud0ou-txfuuk9pva。",
基本上意味着您正在认证的用户无法访问有关的文件,无法找到它。您应该执行一个文件。清单以查看用户可以访问哪些文件。
如果您正在使用服务帐户进行身份验证,则需要确保已授予该服务帐户访问团队驱动器帐户,则它将能够访问文件。