Add/Remove editors in Google sites using Google Apps Script

377 views Asked by At

I am writing a google apps script to process bulk add/remove editors for some new Google Sites. I am aware that google apps script currently doesn't support new google sites so I am trying to use DriveApp to manage the editors. However the script doesn't work and returns the following:

Exception: Service error: Drive

whenever file.addEditor() or file.removeEditor() is used. I guess this just doesn't work for new Google Sites. Are there other workarounds?

1

There are 1 answers

5
pgSystemTester On BEST ANSWER

Make sure you're using the correct FileId with Sites as it's not quite as simple to acquire compared to other file types on Google Drive. When you're editing a Site page, the FileId can be found in the URL between /d/ and /p/.

Example: https://sites.google.com/d/????? this the file id ?????/p/!!!! not here !!!!/edit

I just successfully ran the below code to add/remove editors of a new Google Site.

const zFile= DriveApp.getFileById("????? this the file id ?????");

function addEditor(){
  zFile.addEditor("[email protected]");
}

function removeEditor(){
  zFile.removeEditor("[email protected]");
}