Remove Viewer in Shared Drives folder

149 views
Skip to first unread message

JMR...

unread,
Nov 17, 2023, 9:06:31 PM11/17/23
to Google Apps Script Community
Hi,

I am getting this message when I am trying to remove a specific email address with viewer access. Error is Exception: Cannot use this operation on a shared drive item.

What is the method to remove the viewers/writers in Shared Drives? I also tried this:
DriveApp.getFolderById("XXX").revokePermissions(viewerEmail) but still did not work.

//Scan and remove "te...@test.com" */
var folderViewers = DriveApp.getFolderById("XXX").getViewers();
   var viewerEmail;
      for (var x in folderViewers) {
        viewerEmail = folderViewers[x].getEmail();
        if (viewerEmail === "te...@test.com"") {
           DriveApp.getFolderById("XXX").removeViewer(viewerEmail)
      }
}

Is there a different method to remove viewers, writers etc in Shared Drives? Any help is greatly appreciated.

Thanks!
J -

Emerson Maia

unread,
Nov 18, 2023, 2:10:53 AM11/18/23
to google-apps-sc...@googlegroups.com
Boa noite, será que assim te atenda.

// Substitua "XXX" pelo ID real da pasta
const folderId = "XXX";
const folder = DriveApp.getFolderById(folderId);
const viewers = folder.getViewers();

viewers.forEach(function(viewer) {
  if (viewer.getEmail() === "te...@test.com") {
    folder.removeViewer(viewer);
  }
});

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/7d55a10a-ca6b-4689-a920-d58bd647da3fn%40googlegroups.com.

JMR...

unread,
Nov 20, 2023, 1:48:55 PM11/20/23
to Google Apps Script Community
I did use the same method to remove the email address but I received this Exception: Cannot use this operation on a shared drive item.
Reply all
Reply to author
Forward
0 new messages