'Google Drive API - Searching all shared file in a Drive with query
I'm trying to find out which files in a shared google drive is shared with someone outside the organisation. That includes :
- shared with a public link
- shared in domain
- shared to someone by his email.
Here's an example of what I have without any filtering (post formatted)
[
{
"id": "XXXXXXXXXXXXXXX",
"name": "private but shared to external people",
"permissions": [
{
"id": "XXXXXXXXXXXXXXX",
"type": "user",
"emailAddress": "[email protected]",
"role": "writer"
},
{
"id": "XXXXXXXXXXXXXXX",
"type": "user",
"emailAddress": "[email protected]",
"role": "organizer"
}
]
},
{
"id": "XXXXXXXXXXXXXXX",
"name": "public domain",
"permissions": [
{
"id": "XXXXXXXXXXXXXXX",
"type": "domain",
"role": "reader",
"domain": "xxxxxxxx.com"
},
{
"id": "XXXXXXXXXXXXXXX",
"type": "user",
"emailAddress": "[email protected]",
"role": "organizer"
}
]
},
{
"id": "XXXXXXXXXXXXXXX",
"name": "public",
"permissions": [
{
"id": "anyoneWithLink",
"type": "anyone",
"role": "reader"
},
{
"id": "XXXXXXXXXXXXXXX",
"type": "user",
"emailAddress": "[email protected]",
"role": "organizer"
}
]
},
{
"id": "XXXXXXXXXXXXXXX",
"name": "private",
"permissions": [
{
"id": "XXXXXXXXXXXXXXX",
"type": "user",
"emailAddress": "[email protected]",
"role": "organizer"
}
]
}
]
To filter, I used the query: q: "visibility != 'limited'" but then the file
"private but shared to external people" isn't caught anymore.
So what I want is to create a query to retrieve all files that are shared and all files that are shared to any users that do not belong to the organisation.
I've already coded a manual version of that logic (this is why I can show the permissions array) but I would like to improve performances because it's really long to loop through all files to retrieves their permission and then manually check if the user email belongs to the domain or no.
Thank you :D
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
