Here is my issue:
- I have a folder that I own.
- I set permission of X account to my folder as "writer"
- X account uploads a file to my folder. (X becomes the owner, I become editor/writer/contributor for that file)
- I can move the uploaded file to trash by drive.google.com but not by Drive Api v3
Here is my code:
setTrashedTrue(fileId, callback) {
authenticate(function (auth) {
const drive = google.drive({ version: 'v3', auth });
drive.files.update(
{
fileId,
resource: {
trashed: true
}
},
(err, res) => {
if (err) return console.log('The API returned an error: ' + err);
callback(res);
}
);
});
}
The resource that I use to write the code above: https://developers.google.com/drive/api/v3/reference/files/update
This throws an error that says:
The API returned an error: Error: The user does not have sufficient permissions for this file.
Apparently you can't delete a file that you don't own. Because it tries to delete it permanently. But I should be able to move it to trash as I can do with the web site of drive.
I printed the details of the uploaded file. This is the related result: (Capabilities are for my account, not the owner of the file.)
...
ownedByMe: false,
capabilities: {
...
canDelete: false,
canDownload: true,
canEdit: true,
canListChildren: false,
canModifyContent: true,
canMoveItemIntoTeamDrive: false,
canMoveItemOutOfDrive: false,
canReadRevisions: true,
canRemoveChildren: false,
canRename: true,
canShare: true,
canTrash: false, <--------------
canUntrash: false
}
...
As you see, it tells me that I don't have permission to trash it but in fact I have. So how can I trash a file that doesn't belong to me but shared with me as I am editor?