Class User

使用者

與 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());
}

方法

方法傳回類型簡短說明
getDomain()String|null取得與使用者帳戶相關聯的網域名稱。
getEmail()String|null取得使用者的電子郵件地址。
getName()String|null取得使用者名稱。
getPhotoUrl()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 (如果沒有相片)

已淘汰的方法