我正在尝试使用 Java Google Drive API 将文件移至垃圾箱。这是我尝试做的事情:
代码:
val file = service.files().get(fileId).execute()
file.setTrashed(true)
service.files().update(fileId, file).execute()
错误:
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
POST https://www.googleapis.com/drive/v3/files/0B0XJAu1tqe0ZT01ZSzRLb3Zfa3c
{
"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."
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:118)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:37)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:439)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1111)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:525)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:466)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:576)
at DriveQuickstart.main(DriveQuickstart.kt:97)