Class User

用户

与 Google 云端硬盘中的文件关联的用户。可以通过 File.getEditors()Folder.getViewers() 和其他方法访问用户。

// Log the email address of all users who have edit access to a file.
var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
var editors = file.getEditors();
for (var i = 0; i < editors.length; i++) {
  Logger.log(editors[i].getEmail());
}

方法

方法返回类型简介
getDomain()String获取与用户账号关联的域名。
getEmail()String获取用户的电子邮件地址。
getName()String获取用户的名称。
getPhotoUrl()String获取用户照片的网址。

详细文档

getDomain()

获取与用户帐号关联的域名。

// Log the domain names associated with all users who have edit access to a file.
var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
var editors = file.getEditors();
for (var i = 0; i < editors.length; i++) {
  Logger.log(editors[i].getDomain());
}

弃踢回攻

String - 与用户帐号关联的域名


getEmail()

获取用户的电子邮件地址。仅当用户已在 Google+ 帐号设置页面中选择分享地址时,或者用户属于运行脚本的用户属于同一网域,并且网域管理员允许该网域中的所有用户查看其他用户的电子邮件地址时,用户的电子邮件地址才可用。

// Log the email address of all users who have edit access to a file.
var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
var editors = file.getEditors();
for (var i = 0; i < editors.length; i++) {
  Logger.log(editors[i].getEmail());
}

弃踢回攻

String - 用户的电子邮件地址;如果电子邮件地址不可用,则返回空字符串


getName()

获取用户的名称。如果用户的姓名不可用,此方法会返回 null

// Log the names of all users who have edit access to a file.
var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
var editors = file.getEditors();
for (var i = 0; i < editors.length; i++) {
  Logger.log(editors[i].getName());
}

弃踢回攻

String - 用户的姓名,如果姓名不可用,则为 null


getPhotoUrl()

获取用户照片的网址。如果用户的照片不可用,此方法会返回 null

// Log the URLs for the photos of all users who have edit access to a file.
var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
var editors = file.getEditors();
for (var i = 0; i < editors.length; i++) {
  Logger.log(editors[i].getPhotoUrl());
}

弃踢回攻

String - 用户照片的网址,如果照片不可用,则为 null

已废弃的方法