Reputation: 23
I'm looking for a method to delete the file without having to permanently lose them from google drive using the API v3 for PHP... I mean, I want to trash it.
Looking at the V2 Reference I noticed that there is a direct function to do this, but in V3 it is no longer present and it doesn't work.
/**
* Move a file to the trash.
*
* @param Google_Service_Drive $service Drive API service instance.
* @param String $fileId ID of the file to trash.
* @return Google_Servie_Drive_DriveFile The updated file. NULL is returned if
* an API error occurred.
*/
function trashFile($service, $fileId) {
try {
return $service->files->trash($fileId);
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
return NULL;
}
So, is there a way with Google Drive PHP API V3 to trash a file and/or folder without losing it permanently?
Upvotes: 2
Views: 729
Reputation: 201603
I believe your goal and your current situation as follows.
$service
can be used for moving the file to the trash box.In this case, the method of "Files: update" of Drive API v3 is used. The sample script is as follows.
$fileId = '###'; // Please set the file ID and folder ID.
$metadata = new Google_Service_Drive_DriveFile();
$metadata->setTrashed(true);
$res = $service->files->update($fileId, $metadata);
Upvotes: 3