与 Google 云端硬盘中的文件关联的用户。您可以通过 File.getEditors()、Folder.getViewers() 和其他方法访问用户。
// Log the email address of all users who have edit access to a file. const file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz'); const editors = file.getEditors(); for (let i = 0; i < editors.length; i++) { Logger.log(editors[i].getEmail()); }
方法
| 方法 | 返回值类型 | 简介 |
|---|---|---|
get | String|null | 获取与用户账号关联的域名。 |
get | String|null | 获取用户的电子邮件地址。 |
get | String|null | 获取用户的姓名。 |
get | String|null | 获取用户照片的网址。 |
详细文档
getDomain()
获取与用户账号关联的域名。
// Log the domain names associated with all users who have edit access to a // file. const file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz'); const editors = file.getEditors(); for (let i = 0; i < editors.length; i++) { Logger.log(editors[i].getDomain()); }
返回
String|null - 与用户账号关联的域名
getEmail()
获取用户的电子邮件地址。只有在用户已选择从 Google+ 账号设置页面共享电子邮件地址,或者用户与运行脚本的用户属于同一网域,并且网域管理员已允许网域内的所有用户查看其他用户的电子邮件地址时,用户的电子邮件地址才可用。
// Log the email address of all users who have edit access to a file. const file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz'); const editors = file.getEditors(); for (let i = 0; i < editors.length; i++) { Logger.log(editors[i].getEmail()); }
返回
String|null - 用户的电子邮件地址;如果电子邮件地址不可用,则为空字符串
getName()
获取用户的姓名。如果用户的姓名不可用,此方法会返回 null。
// Log the names of all users who have edit access to a file. const file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz'); const editors = file.getEditors(); for (let i = 0; i < editors.length; i++) { Logger.log(editors[i].getName()); }
返回
String|null - 用户的姓名;如果姓名不可用,则为 null
getPhotoUrl()
获取用户照片的网址。如果用户照片不可用,此方法会返回 null。
// Log the URLs for the photos of all users who have edit access to a file. const file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz'); const editors = file.getEditors(); for (let i = 0; i < editors.length; i++) { Logger.log(editors[i].getPhotoUrl()); }
返回
String|null - 用户照片的网址;如果照片不可用,则为 null