Google TeamDrive файлы -> получить команду, файл не найден

Я смог найти команду teamdrive очень хорошо, но я не мог использовать команду file get для загрузки искомого файла с использованием учетной записи службы.

$client = new Google_Client();
$client->setApplicationName('Google Drive API PHP Quickstart');
$client->setScopes(Google_Service_Drive::DRIVE);
$client->setAuthConfig(__DIR__ . '/api-access-221800-67b8a6c7d16d.json');
//$client->setAccessType('offline');
$service = new Google_Service_Drive($client);

// Print the names and IDs for up to 10 files.
$optParams = array(
'pageSize' => 20,
'corpora' => "user,allTeamDrives",
'includeTeamDriveItems' => true,
'q' => "name contains '606399' and mimeType != 'application/vnd.google-apps.folder'",
'supportsTeamDrives' => true
);
$results = $service->files->listFiles($optParams);
echo '<pre>';
print_r($results);
echo '</pre>';
if (count($results->getFiles()) == 0) {
print "No files found.\n";
} else {
print "Files:\n";
foreach ($results->getFiles() as $file) {
printf("%s (%s)\n", $file->getName(), $file->getId());
}
}

$response = $service->files->get(array(
'fileId' => "1bzEsw6Wrj_aNQPZOS7jlpK6mBYXS9SWU",
'alt' => 'json',
'acknowledgeAbuse' => true,
'supportsTeamDrives' => true
));

$content = $response->getBody()->getContents();

Выход этого приложения является следующим ..

Google_Service_Drive_FileList Object
(
[collection_key:protected] => files
[filesType:protected] => Google_Service_Drive_DriveFile
[filesDataType:protected] => array
[incompleteSearch] =>
[kind] => drive#fileList
[nextPageToken] =>
[internal_gapi_mappings:protected] => Array
(
)

[modelData:protected] => Array
(
[files] => Array
(
[0] => Array
(
[kind] => drive#file
[id] => 1hoaB13IcMZWKSlCuKIHtfYcr3-O4xO-2
[name] => 606399 USDA.pdf
[mimeType] => application/pdf
[teamDriveId] => zzzRemoved
)

[1] => Array
(
[kind] => drive#file
[id] => 1et_2Kau97OCkhk8-t9Ctx-pnZlp1ha8d
[name] => 606399 Kernel Pic.JPG
[mimeType] => image/jpeg
[teamDriveId] => zzzRemoved
)

[2] => Array
(
[kind] => drive#file
[id] => 1bzEsw6Wrj_aNQPZOS7jlpK6mBYXS9SWU
[name] => 606399 Load Docs.pdf
[mimeType] => application/pdf
[teamDriveId] => zzzRemoved
)

)

)

[processed:protected] => Array
(
)

)
Files: 606399 USDA.pdf (1hoaB13IcMZWKSlCuKIHtfYcr3-O4xO-2) 606399 Kernel Pic.JPG (1et_2Kau97OCkhk8-t9Ctx-pnZlp1ha8d) 606399 Load Docs.pdf (1bzEsw6Wrj_aNQPZOS7jlpK6mBYXS9SWU)
Fatal error: Uncaught Google_Service_Exception: { "error": { "errors": [ { "domain": "global", "reason": "notFound", "message": "File not found: fileId,1bzEsw6Wrj_aNQPZOS7jlpK6mBYXS9SWU,alt,json,acknowledgeAbuse,1,supportsTeamDrives,1.", "locationType": "parameter", "location": "fileId" } ], "code": 404, "message": "File not found: fileId,1bzEsw6Wrj_aNQPZOS7jlpK6mBYXS9SWU,alt,json,acknowledgeAbuse,1,supportsTeamDrives,1." } } in C:\xampp\htdocs\gapi\vendor\google\apiclient\src\Google\Http\REST.php:118 Stack trace: #0 C:\xampp\htdocs\gapi\vendor\google\apiclient\src\Google\Http\REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #1 C:\xampp\htdocs\gapi\vendor\google\apiclient\src\Google\Task\Runner.php(181): Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2 C:\xampp\htdocs\gapi\vendor\google\apiclient\src\Google\Http\REST.php(58): Google_ in C:\xampp\htdocs\gapi\vendor\google\apiclient\src\Google\Http\REST.php on line 118

Я смог использовать тестер api rest google drive rest, чтобы получить ответ json с такими же параметрами здесь, https://developers.google.com/drive/api/v2/reference/files/get

конечная цель — загрузить файл, на который нажал пользователь.

1

Решение

Вам нужно передать необязательные параметры для запроса вашего файла в качестве второго аргумента, сигнатуру метода для files->get() является get($fileId, $optParams = array()), Так что если вы измените свой код на следующий, он должен работать:

$response = $service->files->get("1bzEsw6Wrj_aNQPZOS7jlpK6mBYXS9SWU", array(
'alt' => 'json',
'acknowledgeAbuse' => true,
'supportsTeamDrives' => true
));

Определение метода можно найти Вот

1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector