![](/img/trans.png)
[英]Upload file into particular folder on Google Drive using PHP and Drive API
[英]How to delete a file in a google drive shared drive folder using php?
我只需要使用 php 使用 google/apiclient 删除我的共享驱动器文件夹中的文件,这是我下面的代码。
session_start();
require __DIR__ . '/vendor/autoload.php'; // ready the API to upload to drive
use Google\Client;
use Google\Service\Drive;
if (isset($_POST['file'])) {
$file = $_POST['file'];
$client = new Client();
putenv('GOOGLE_APPLICATION_CREDENTIALS=./credentials.json');
$client->useApplicationDefaultCredentials();
$client->addScope(Drive::DRIVE);
$driveService = new Drive($client);
$delete = $driveService->files->delete($file);
if ($delete) {
$_SESSION['success'] = "Video deleted successfully";
header("Location: upload");
}
}
如果你的客户端有删除共享Drive文件的权限,下面的修改怎么样?
$delete = $driveService->files->delete($file);
$fileId = "###"; // Please set the file ID of the file you want to delete.
try {
$driveService->files->delete($fileId, array('supportsAllDrives' => true));
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.