Google ドライブで特定のプレゼンテーション/ドキュメントの「共有」閲覧権限を取得した人の包括的なリストが必要です。スクリーン ショットがありますが、十分ではない可能性があります。この情報をプログラムで取得するにはどうすればよいでしょうか?
2733 次
2 に答える
2
オブジェクトに関連付けられた属性には、File
次の 3 つのユーザー関連項目が含まれます。
- 所有者- を使用して取得された単一の
User
オブジェクトFile.getOwner()
。 - 編集者
Users
-を使用して取得された、ファイルの編集権限を持つユーザーの配列File.getEditors()
。所有者を含みます。 - Viewers
Users
-を使用して取得された、ファイルに対する読み取り専用の表示権限を持つの配列File.getViewers()
。所有者を含みます。
これらは、ファイルの所有者のみがプログラムで取得できます。
次の関数は、ゴミ箱に移動した Google ドライブ ファイルをターゲット フォルダーに復元するユーティリティです。この関数は、指定されたまたはgetFileInfo()
の属性を持つオブジェクトを返します。これには、エディタとビューアが含まれます。編集者リストと閲覧者リストの所有者は無視されます。これを自分の状況に合わせて自由に調整してください。注:この gistにある追加のユーティリティ関数に依存しています。File
Folder
/**
* Return an object containing relevant information about the given file.
* See https://developers.google.com/apps-script/class_file.
* From: https://gist.github.com/mogsdad/4644369
*
* @param {Object} file File or Folder object to examine.
*
* @return {Object} Interesting file attributes.
* <pre>{
* id: unique id (ID) of the folder or file
* name: the name of the File
* size: the size of the File
* type: The type of the file
* created: date that the File was created
* description: the description of the File
* owner: user id of the owner of the File
* otherViewers: list of user ids of viewers of the File, w/o owner
* otherEditors: list of user ids of editors of the File, w/o owner
* }</pre>
*/
function getFileInfo (file) {
var fileInfo = {
id: file.getId(),
name: file.getName(),
size: file.getSize(),
type: (file.getMimeType) ? docTypeToText_(file.getMimeType()) : "folder", // DriveApp Folders don't have getMimeType() method.
created: file.getDateCreated(),
description: file.getDescription(),
owner: userNames([file.getOwner()],false),
otherViewers: userNames(file.getViewers(),true),
otherEditors: userNames(file.getEditors(),true)
};
return fileInfo;
}
ファイルの属性の例を次に示します。
{ "id": "0B2kSPNhhUowaRGZKY3VGLUZCREk",
"name": "Rescued Files",
"size": 0,
"type": "folder",
"created": "2016-06-13T20:18:14.526Z",
"description": "",
"owner": "user@example.com",
"otherViewers": "none",
"otherEditors": "none"
}
特典内容
以下は、Google ドライブ内のすべてのファイルとフォルダーをスキャンし、ユーザー情報を含むログを生成するスクリプトです。(タイムアウトを回避するための規定はありません。注意してください。)
/**
* Generate logs with user sharing info for all files & folders.
*/
function showSharing() {
var files = DriveApp.getFiles();
var folders = DriveApp.getFolders();
while (files.hasNext() || folders.hasNext()) {
var iterator = files.hasNext() ? files : folders;
Logger.log(JSON.stringify(getFileInfo(iterator.next())));
}
}
于 2013-03-04T03:14:15.133 に答える