내 teamdrive에 파일을 업로드하고 싶지만 실패합니다. 내 드라이브에 업로드 작업.Drive API 및 PHP가 포함 된 Teamdrives에 파일 업로드
내 Teamdrive에 폴더 ID가있는 배열과 팀 드라이브 ID가있는 로컬 파일로 함수를 호출합니다. $ service Google_Service_Drive 개체 및 $ client Google_Client
supportTeamDrives 옵션을 사용합니다.
listFiles를 시도하면 Teamdrives도 존재하지 않습니다.
PHP에서 API를 통해 Teamdrives에 액세스하려면 어떻게해야합니까?
이 버전은 이제 작동합니다
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."
}
}
답장을 보내 주셔서 감사합니다. 사용자가 팀 드라이브에 대한 권한을 가지고 있으며 앱이 Google_Service_Drive :: DRIVE (전체 액세스)를 사용합니다 Teamdrive 용으로 다른 범위가 필요합니까? 사용자가 팀 드라이브 – yannik995
에 대한 전체 액세스 권한을 가진 다음 file.list를 사용하여 사용자가 액세스 할 수있는 파일을 확인합니다. 만약 그들이 파일에 접근 할 수 없다면 그들에게 접근을 허용 할 필요가 있습니다. – DaImTo
$ service-> teamdrives-> listTeamdrives를 사용한다면 (Teamdrives를 모두 얻습니다.) 나는 Fullaccess를 가지고 Teamdrives를 만든 사람입니다. – yannik995