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

Methods

メソッド戻り値の型概要
getDomain()Stringユーザーのアカウントに関連付けられているドメイン名を取得します。
getEmail()Stringユーザーのメールアドレスを取得します。
getName()Stringユーザーの名前を取得します。
getPhotoUrl()Stringユーザーの写真の URL を取得します。

詳細なドキュメント

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()

ユーザーの写真の URL を取得します。ユーザーの写真を利用できない場合、このメソッドは 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 - ユーザーの写真の URL。写真を使用できない場合は null

サポート終了のメソッド