Google drive API - list files with its permissions

Viewed 2154

I want to list files and its permissions by this API https://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

enter image description here

Do anyone know what is wrong?

2 Answers

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"

Related