Simple function here in Google Apps Script:
function driveSearch() {
// Log the name of every file in the user's Drive whose visibility is anyonewithLink or anyonecanfind
var files = DriveApp.searchFiles(
'visibility = "anyoneWithLink" or visibility = "anyoneCanFind"');
while (files.hasNext()) {
var file = files.next();
var owner = file.getOwner().getName();
var sa = file.getSharingAccess();
Logger.log(file.getName());
Logger.log('Owner:'+owner);
Logger.log("SharingAccess:"+sa);
}
}
It want to find shared files in my gsuite drive.
However, it says I don't have permissions to run DriveApp
My permissions are set and requested correctly, like so:
{
"timeZone": "America/New_York",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER",
"oauthScopes": [
"https://www.googleapis.com/auth/drive.readonly",
"https://www.googleapis.com/auth/drive.metadata.readonly"
]
}
The error is
You do not have permission to call DriveApp.searchFiles. Required permissions: https://www.googleapis.com/auth/drive (line 3, file "Code")
Why does searchFiles require delete permissions? I am very worried about inadvertent deletion, I don't want the full scope. Is there something else I'm doing wrong?
Lastly, yes my Gsuite allows Google Apps Script.
searchFiles()in Class DriveApp uses the scope ofhttps://www.googleapis.com/auth/drive. It seems that this is the specification. If you don't want to use the scope ofhttps://www.googleapis.com/auth/drive, how about this workaround? In this workaround, the endpoint of Drive API is directly requested by UrlFetchApp. But in this case, 2 scopes ofhttps://www.googleapis.com/auth/drive.metadata.readonlyandhttps://www.googleapis.com/auth/script.external_requestare required. Because I'm not sure whether this is what you want, I posted it as a comment. - Tanaike