Delete the file that was previously added from Shared With Me to My Drive.

Google Drive has a great feature: you can add a file or folder from Shared With Me to My Drive.

enter image description here

Then I can delete this file from My drive in the same way (note that if I delete the shared file in the web version, it wonโ€™t go to the trash)

enter image description here

However, I get a 403 Forbidden error when I try to delete this file using the Google Drive API (due to insufficient permissions, because of this I do not own this file). So, as you can see, this is not a simple delete request. How can I implement this functionality?

+6
source share
3 answers

Add to my drive changes the collection of parents for the subject in question. To change this, you will want to delete this item, not delete it.

Use the about.get call to retrieve the identifier of my disk, and then remove this identifier from the list of parents in the file resource for the file / folder. Update the file with the new list of parents.

+2
source

Late answer, but I came across this question. This is because the file is not actually copied, it is the same instance. If you delete it from my drive, it will also be deleted from the shared drive. You may not be able to remove it from the shared drive.

If you just want to remove it from my disk: click on the file. In the right pane, under the Details section, thereโ€™s a list of locations. At least the shared drive and my drive are listed here. Press X to delete it from My Drive, and it will disappear there, saving it to the shared drive.

+1
source

Here is what I found. After deleting the parent item available to me, search for sharedWithMe as before, returning the item even if the parent list of items is empty.

Here is the code:

 string sItemId = (this is the Id of the item shared with me); string sParentId = driveService.About.Get().Execute().RootFolderId; driveService.Parents.Delete(sItemId, sParentId).Execute(); var parentList = m_driveService.Parents.List(sItemId).Execute(); 

At this moment parentList.Items.Count is 0 .

Now when I search for sharedWithMe , the item is in the return list.

0
source

Source: https://habr.com/ru/post/983880/


All Articles