How to Remove Access from Shared Folder in Google Drive API

I’m working on removing access permissions from a shared folder using the Google Drive API but I can’t get it to work properly. I’ve been trying to fetch the permission list and remove entries one by one but something is going wrong.

Here’s what I’m attempting:

PermissionFeed permFeed = folder.getPermissionFeed();
for (PermissionEntry perm : permFeed.getEntries()) {
    perm.remove();
}

I’m also not completely sure about the correct endpoint URL format for accessing the folder permissions. Should I be using a different approach to revoke sharing access from a collection? Any help would be appreciated.

You’re encountering a concurrent modification issue; removing permissions while iterating through them won’t work correctly. Instead, first collect all the permission IDs and remove them afterwards in a separate operation. Additionally, ensure that you have the correct authentication scopes set up; you should be using the full drive scope rather than the readonly option. If you are still using the old API, the URL should be /feeds/default/private/full/folder%3Afolder_id/acl. However, I recommend transitioning to the newer REST API as it offers improved error handling and supports batch operations.

hey! ur on the old gdata API. u should switch to the v3 REST API - way better. try files.permissions.delete() with ur file id & perm id. much more reliable than what ur doing now.

This is a common issue with the older GData API. You can’t modify a collection while iterating through it directly - that’s what’s causing your problem. I’ve dealt with this before and found that creating a reverse loop through the permission entries prevents the index shifting issues. But honestly, I’d recommend switching to Drive API v3 instead. The GData approach is deprecated anyway. When I made the switch, permissions.list() and permissions.delete() were way more straightforward to work with. Just make sure you’re using the right file ID format and remember that owner permissions can’t be removed. Also double-check that your OAuth scopes include the necessary drive permissions.