Google Spreadsheet — get sharing permissions by script

笑着哭i 提交于 2019-12-13 00:56:29

问题


Is it possible to get list of users and permissions from google spreadsheet by javascript?

I have several spreadsheets on shared google drive and I want to check , how are set sharing permissions by script. I am sharing these spreadsheets with more than 20 another users, so it is difficult to check every spreadsheet manually.

Is it possible?

And is it possible to run some script also above whole google drive? For example if I would like to get list of all google spredsheets and folders on drive with sharing permissions list, can I write some javascript above google drive?

Thank you very much


回答1:


Disclaimer - This is my first Goolge Apps script, so I'm not 100% sure this is what you want.

I used the DocsList API to list the owner, the editors and the viewers of every spreadsheet in a given Google Drive folder:

function start() {
  var folder = DocsList.getFolderById("...put folder ID here..."),
      files = folder.getFilesByType(DocsList.FileType.SPREADSHEET), file = null, spreadsheet = null,
      owner = null, editors = null, editor = null, viewers = null, viewer = null,
      i = 0, j = 0;

  for (i = 0; i < files.length; i += 1) {
    file = files[i];
    Logger.log("===== Spreadsheet " + (i + 1) + "/" + files.length + ": " + file.getName() + " =====");
    spreadsheet = SpreadsheetApp.openById(file.getId());
    owner = spreadsheet.getOwner();
    Logger.log("- Owner: " + owner.getEmail());
    editors = spreadsheet.getEditors();
    for (j = 0; j < editors.length; j += 1) {
      editor = editors[j];
      Logger.log("- Editor " + (j + 1) + "/" + editors.length + ": " + editor.getEmail());
    }
    viewers = spreadsheet.getViewers();
    for (j = 0; j < viewers.length; j += 1) {
      viewer = viewers[j];
      Logger.log("- Viewer " + (j + 1) + "/" + viewers.length + ": " + viewer.getEmail());
    }
  }
}

Note that the list of viewers contains the commenters too, these two groups are not seprated by this API. I tested this code, and it works for me. You can easily generalize it to iterate over every folder.



来源:https://stackoverflow.com/questions/26136616/google-spreadsheet-get-sharing-permissions-by-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!