Reputation: 41
Intro: Alice prepared an app script that is bound to a Google Sheet. The script generates a Google Doc from the Google Sheet. The doc is stored on Alice's Google Drive. If Alice generates a new Google Doc, then the old one is deleted. The following code is used for that.
function delteFile(myFileName) {
var allFiles, idToDLET, myFolder, rtrnFromDLET, thisFile;
myFolder = DriveApp.getFolderById("folder_id_is_here");
allFiles = myFolder.getFilesByName(myFileName);
while (allFiles.hasNext()) {
thisFile = allFiles.next();
idToDLET = thisFile.getId();
rtrnFromDLET = Drive.Files.remove(idToDLET); // API call to drive.files.delete failed with error: Insufficient permissions for this file
};
};
Alice shared the project on Google Cloud Platform with Bob.
API call to drive.files.delete failed with error: Insufficient permissions for this file
Alice can successfully execute the above code in this case.
Question: The project is shared on Google Cloud Platform. What else does Alice need to share?
Upvotes: 4
Views: 1890
Reputation: 402
The proper tool for this problem is Google Shared Drive. But if that doesn't work in your situation, you can make your own trash folder (e.g. 'ToTrash'). Then give to the people that can trash, permission to this folder. Instead of trashing you let people use a script (see below) that moves files to your own 'ToTrash' folder. Once in a while you delete all files in the 'ToTrash' folder. For that you can also write a script (not provided but easy to write) that is automatically triggered for example once every day.
// TRASHFOLDERID is the Id of your own created trash folder.
// 'file' is a file object you constructed
// by getting it by id, name, or FileIterator
const trashFolder = DriveApp.getFolderById(TRASHFOLDERID);
file.moveTo(trashFolder);
Upvotes: 0