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

已淘汰的方法