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

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」でコピーをして、貼り付けを行うことで確認できます。

-
前の記事
javascript setの差分を取得する 2022.11.08
-
次の記事
GAS 実行を行うショートカットキー 2022.11.08
コメントを書く