简体   繁体   中英

Google drive API - list files with its permissions

I want to list files and its permissions by this APIhttps://developers.google.com/drive/api/v3/reference/files/list

When I set fields to * or explicitly set

  • files(id,name,description,mimeType,parents,trashed, permissions/*))
  • files(id,name,description,mimeType,parents,trashed, permissions(*))
  • files(id,name,description,mimeType,parents,trashed, permissions/emailAddress)

I will never receive permissions.

I am getting this:

{
   "id": "abc123"
   "name": "Name of file",
   "mimeType": "application/vnd.google-apps.folder",
   "trashed": false,
   "parents": [
      "abc1234"
   ]
}

Also, I have noticed the API doesn't return NULL values (description), but the permission is not NULL when I fetch it by https://developers.google.com/drive/api/v3/reference/permissions/get .

Here is what I call in "Try this API".

curl \
  'https://www.googleapis.com/drive/v3/files?supportsAllDrives=true&fields=files(id%2Cname%2Cdescription%2CmimeType%2Cparents%2Ctrashed%2Cpermissions)&key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed

在此处输入图像描述

Do anyone know what is wrong?

Get all permissions

files(id,name,description,mimeType,parents,trashed,permissions)

Returns.

 {
   "id": "1nsFyMDBDkeuLYx0oDIk9vQFOMH4Vc98ndxIG4Giq6Y",
   "name": "Copy of How to create an credentails.json",
   "mimeType": "application/vnd.google-apps.presentation",
   "trashed": false,
   "parents": [
    "1dIyzPuh2XFVdlhJa4wSzNTlyCRguypI"
   ],
   "permissions": [
    {
     "kind": "drive#permission",
     "id": "0603058822553437243",
     "type": "user",
     "emailAddress": "me@gmail.com",
     "role": "owner",
     "displayName": "Linda Lawton",
     "photoLink": "https://lh3.googleusercontent.com/a-/AOh14GhroCYJp2P9xYeYk1npchBPK-zbtTxzNQo0WAHI20=s64",
     "deleted": false
    }
   ]
  },

Just get the email permission

files(id,name,description,mimeType,parents,trashed,permissions(emailAddress))

returns

 {
   "id": "1igmEhcgLrVFyneIcwFTetsFe-eDwKDsRqTmMwHaibs",
   "name": "Copy of Copy of How to create an api key",
   "mimeType": "application/vnd.google-apps.presentation",
   "trashed": false,
   "parents": [
    "1yqppb5v5jSzCqnQaO8svooJh3C9nH3G"
   ],
   "permissions": [
    {
     "emailAddress": "me@gmail.com"
    }
   ]
  },

It seems to work fine for me.

files(id, name, md5Checksum, size, parents, mimeType, webContentLink, permissionIds)

add "permissionIds" that between the returned data you will receive an array with the id of all permissions, in the case of files with "anyone" sharing the returned id is "anyoneWithLink"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM