用户可以上传但不能删除共享驱动器上的文件

时间:2019-07-01 16:50:08

标签: google-drive-api

我正在使用REST API创建[1],列出[2]和删除[3]文件。

具有内容管理员权限的用户可以将文件创建到共享驱动器。 该用户还可以列出驱动器内容。 但是,当尝试使用以下命令删除同一文件时:

DELETE /drive/v3/files/<fileid>?supportsAllDrives=true

这样的主体返回403禁止错误:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "insufficientFilePermissions",
    "message": "The user does not have sufficient permissions for this file."
   }
  ],
  "code": 403,
  "message": "The user does not have sufficient permissions for this file."
 }
}

可以使用Google API资源管理器进行复制。

编辑:

关于get [4]返回

GET https://www.googleapis.com/drive/v3/about?supportsAllDrives=true

{
 "user": {
  "kind": "drive#user",
  "displayName": "Jessy Hurley",
  "me": true,
  "permissionId": "03805955809493222960",
  "emailAddress": "jessyhurley@ondazultecnologia.com"
 }
}

权限获得[5]回报

GET https://www.googleapis.com/drive/v3/files/1PWntiqRbg3ZhPdqkNBAv7_NpevGrHsO1/permissions/03805955809493222960?supportsAllDrives=true

{
 "kind": "drive#permission",
 "id": "03805955809493222960",
 "type": "user",
 "role": "fileOrganizer"
}

[1] https://developers.google.com/drive/api/v3/reference/files/create

[2] https://developers.google.com/drive/api/v3/reference/files/list

[3] https://developers.google.com/drive/api/v3/reference/files/delete

[4] https://developers.google.com/drive/api/v3/reference/about/get

[5] https://developers.google.com/drive/api/v3/reference/permissions/get

1 个答案:

答案 0 :(得分:0)

内容管理员无法从[6]中永久删除文件。 因此,我使用[7]将呼叫更改为移至垃圾箱:

PATCH https://www.googleapis.com/drive/v3/files/1PWntiqRbg3ZhPdqkNBAv7_NpevGrHsO1?supportsAllDrives=true
{
  "trashed": true
}   

[6] https://support.google.com/a/answer/7337554?hl=en

[7] https://developers.google.com/drive/api/v3/reference/files/update