Delete the file completely from the shared folder

I am trying to delete a file that is shared with Google Drive API, but since I do not own the file, I get a permission error. I looked on the Internet and found this solution . I implemented the solution as shown below:

About about = service.about().get().execute(); String rootId = about.getRootFolderId(); service.parents().delete(fileId, rootId).execute(); 

However, I cannot delete the file using this code. It does not give any errors, but I still see the file on my Google drive.

PS: I checked the fileId parameter and refer to the correct file.

0
source share
1 answer

Sorry, I do not know java, so I could not provide a sample code.

So, in Google Drive API V3, you can no longer get the root folder identifier using the getRootFolderId method using the "About Resource" command.

Instead, you need to use the file.get method, use root (instead of the file identifier) ​​as fileId and request an additional id field (pass ?fields=id ) to get rootFolderId.

In the V3 API driver, by default they stopped returning the full resource. So be careful if you use any code related to V2.

Check out the Fields Section in the google api migration white paper.

Hope this helps.

thanks

0
source

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


All Articles