![](/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.