I’m working on a project where I need to remove sharing permissions from a Google Drive folder, but I’m having trouble figuring out the correct approach.
I’ve been attempting to fetch the permissions list and delete the entries, but my current implementation isn’t working as expected:
I’m also unsure about the correct endpoint URL format for accessing folder permissions. Should I be using a different API endpoint or method to accomplish this task? Any guidance on the proper way to revoke sharing access would be really helpful.
Been dealing with Drive API permissions for years - there’s one gotcha that constantly trips people up. The permissions you’re trying to delete might’ve been created with different sharing settings, and some need extra parameters. When I hit similar issues, I needed to handle the sendNotificationEmail parameter properly. Try setting it to false when calling delete - avoids notification failures that can silently kill the whole operation. Also check if you’re dealing with inherited permissions from parent folders. Those behave differently and you might need to address the folder hierarchy first. The API’s finicky about timing too, so add a small delay between delete calls if you’re processing many permissions at once.
You’re calling perm.remove() on the Permission object, but that’s not how the Drive API works. You need permissions().delete() from the Drive service instead.
Here’s what worked for me:
PermissionList permissions = driveService.permissions().list(folderId).execute();
for (Permission permission : permissions.getPermissions()) {
if (!"owner".equals(permission.getRole())) {
driveService.permissions().delete(folderId, permission.getId()).execute();
}
}
Don’t try deleting the owner permission - it’ll throw an error. Also, it’s PermissionList not PermissionsList in newer API versions. The client library handles the /drive/v3/files/{fileId}/permissions/{permissionId} endpoint when you use the delete method.
hit this exact problem last week! double-check ur using the right drive service instance and verify ur app has the correct scopes enabled. delete calls fail silently w/o proper permissions. pro tip: batch requests are way more efficient when removing multiple permissions.