返回文档所有者以获取Google云端硬盘文档ID的大量列表 [英] returning document owner for large list of Google Drive doc IDs

查看:82
本文介绍了返回文档所有者以获取Google云端硬盘文档ID的大量列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试识别Google云端硬盘中一长串文档(近1000项)的所有者.所有者可能在文档之间有所不同.每个项目都有唯一的文档ID.

I am trying to identify the owner of a long list (almost 1000 items) of documents within Google Drive. The owners may vary between the docs. I have the unique doc ID for each item.

我是我域中Google Apps的管理员,并且拥有一个实用程序,可让我输入文档ID,并查看该特定项目的所有权.但是,我必须一次通过一个Web界面执行此操作.

I'm the admin for Google Apps at my domain, and have a utility that lets me punch in a doc ID, and see the ownership of that particular item. However, I have to do this through a web interface, one at a time.

是否有任何一种方法可以利用Google的API(例如在电子表格中),当给定文档ID时,该API可以返回文档的所有者?还是Google脚本?

Is there any way to leverage Google's API, say in a spreadsheet, that can return a document's owner when given the doc ID? Or Google scripts perhaps?

推荐答案

与我的一位同事合作,生成了效果很好的以下Google Apps脚本.

Worked with a colleague of mine to generate the following Google Apps script that works great.

用法:在D列中具有文档ID的列表,突出显示要检查的行(任何单元格都可以,只需在所需的行中突出显示某些内容),然后使用自定义的自动化"菜单执行.

Usage: With a list of doc ID's in column D, highlight the rows you want to check (any cells are fine, just have something highlighted in the desired rows) and execute using the custom "Automation" menu.

结果:然后在E列中返回所有者.

Result: Owner is then returned in column E.

function getOwnerFromValue(val){
  var doc = DriveApp.getFileById(val);
  var user = doc.getOwner();
  return user;
}


function scanRange() {
var range = SpreadsheetApp.getActiveRange();
  var start = range.getRow();
  var stop = range.getLastRow();
  var range = SpreadsheetApp.getActive().getRange("D"+start+":D"+stop)
  var resultRange = SpreadsheetApp.getActive().getRange("E"+start+":E"+stop);
  var result = [];
  range.getValues().forEach(function(obj){
    obj = obj[0];
    if(obj.trim() != "")
      result.push([getOwnerFromValue(obj).getEmail()]);
  });
  resultRange.setValues(result);
}

function onOpen(){
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var entries = [{
    name : "Get Owners' User",
    functionName : "scanRange"
  }];
    sheet.addMenu("Automation",entries);
}


function onAdd(e){
  var editted = e.range;
  if(editted.getRow() != 1 && editted.getColumn() == 4) {
    Logger.log(getOwnerFromValue(editted.getValue()));
  }
}

这篇关于返回文档所有者以获取Google云端硬盘文档ID的大量列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆