GAS エラー「Exception: Unexpected error while getting the method or property getFileById on object DriveApp.」が発生した場合の対処法

GAS エラー「Exception: Unexpected error while getting the method or property getFileById on object DriveApp.」が発生した場合の対処法

GAS(Google Apps Script)で、エラー「Exception: Unexpected error while getting the method or property getFileById on object DriveApp.」が発生した場合の対処法を記述してます。「getFileById」で指定しているidの間違いで発生します。

環境

  • OS windows11 home
  • ブラウザ chrome 107.0.5304.88

エラー全文

以下のコードを、実行時に発生

function myFunction() {

  // idから取得
  let f = DriveApp.getFileById('aaaaaa');

  console.log( f.getDescription() );

}

エラー全文

Exception: Unexpected error while getting the method or property getFileById on object DriveApp.
myFunction	@ コード.gs:4

画像

原因

「getFileById」で存在しない「id」を指定しているため

対処法

存在する「id」を指定する

ファイルやフォルダのidは、対象を「Ctrl」+「C」でコピーをして、貼り付けを行うことで確認できます。