0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Java / Google Drive APIでファイルをごみ箱に入れる方法

Posted at

結論

File file = new File();
file.setTrashed(true);
service.files().update(Id, file).execute();

以上。

補足

Python, Node.jsでの書き方は公式ドキュメントを参照されたし。https://developers.google.com/drive/api/guides/delete?hl=ja#python_1

すでにアップロードされているファイルをservice.files().get(Id)で取得し、.setTrash(true).execute()として直接書き込むことはできない。やろうとすると以下のエラーが出る。

{
  "code": 403,
  "errors": [
    {
      "domain": "global",
      "message": "The resource body includes fields which are not directly writable.",
      "reason": "fieldNotWritable"
    }
  ],
  "message": "The resource body includes fields which are not directly writable."
}

また、ファイルを削除したい場合はservice.files().delete(Id).execute()でできるが、service.files().trash(Id).execute()は使えない。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?