Reputation: 143
I'm trying to get folder and file permissions which is located in Shared Drive. All I can get is permissions list for root Shared Drive but trying to run below code on any ID of file or folder inside throw error.
Relavant Facts
Script
function getPermissions_(driveFileID, sharedDriveSupport){
var thisDrivePermissions = Drive.Permissions.list(
driveFileID,
{
useDomainAdminAccess: USE_DOMAIN_ADMIN_ACCESS,
supportsAllDrives: sharedDriveSupport
}
);
return thisDrivePermissions;
}
Errors
GoogleJsonResponseException: API call to drive.permissions.list failed with error: Shared drive not found: xxxxxxxx
GoogleJsonResponseException: API call to drive.permissions.list failed with error: File not found:
How can I get the file permissions list in Google Shared Drive with Apps Script?
Upvotes: 0
Views: 1956
Reputation: 2416
If I understand correctly, you need to list all the permissions that a drive file contained in a folder from a shared drive has. To do that, you may check the following script as an example:
function myFunction() {
var driveFileID = "FILE ID";
var sharedDriveSupport = true;
var request = {
"supportsAllDrives": sharedDriveSupport,
"useDomainAdminAccess": true,
"fields": "permissionIds"
};
var permissionsRequest = {
"supportsAllDrives": sharedDriveSupport,
"fields": "role"
};
var permissionsIDs = Drive.Files.get(driveFileID, request);
for(var i=0; i<permissionsIDs.permissionIds.length; i++)
{
Logger.log((Drive.Permissions.get(driveFileID, permissionsIDs.permissionIds[i], permissionsRequest)).role);
}
}
This is how it would display the information, by listing all the permission types from the specified file:
Note that this works because you mentioned you have access to the shared drive, however as Rubén mentioned in his answer Google Workspace admins do not have access to all the files, just to the ones that are shared with them, and if you want to have access you can do it using domain wide delegation and user impersonation.
References:
Upvotes: 1
Reputation: 38131
As superadminin you don't have access to all files by default through Google Drive user interface / Google Apps Script. In order to get access to all files in your domain throught Apps Script you have to make use of domain-wide deletegation of authority.
The "not found" errors might occur because the file or shared drive ids are wrong or you don't have access, do double check that the ids are correct and that you passing the parameters correctly. For this you could use Logger.log / console.log to print the variable values to the execution log or use the Apps Script debugger.
Related
Upvotes: 1