Is there any way to see all publicly shared Google Drive items/documents from a specific Google user?
2 Answers
I wrote a Google Apps Script macro that you can attach to a new spreadsheet (or an old one, if it would make any sense) that accomplishes this task. To attach a script to a spreadsheet, go into that spreadsheet (or create a new one), click "Tools"->"Script editor...", copy and paste the code into the editor, click "Resources"->"Current project's triggers," select "onOpen" under Run, select "From spreadsheet" under Events, make sure the third drop-down menu reads "On open," then save the script under a name of your choice.
The code below:
- asks you to enter the email address of the user for whom you want to get a list of shared files
- creates a new sheet within the active spreadsheet
- populates it with two columns of data: one with the names of all of the publicly shared files owned by the user you specified AND live hyperlinks to those files, and a second column containing the names of the folders containing these files
Here's the code:
function doGet() {
var owner = SpreadsheetApp.getUi().prompt("Enter owner's email address:").getResponseText();
var ssheet = SpreadsheetApp.getActive();
var newSheet = ssheet.insertSheet(owner);
newSheet.getRange('A1:B1').setValues([["File Name","Containing Folder"]]);
newSheet.getRange('A1:B1').setFontWeight("bold");
var cells = newSheet.getRange('A1:B500');
var files = DriveApp.getFiles();
var ownerFiles = [];
while (files.hasNext()){
var file = files.next();
if (file.getOwner().getEmail()==owner && file.getSharingAccess()==DriveApp.Access.ANYONE) {
ownerFiles[ownerFiles.length]=file;
}
}
for (i=0; i<ownerFiles.length; i++){
cells.getCell(i+2,1).setValue("=HYPERLINK(" + ownerFiles[i].getUrl() + "," + ownerFiles[i].getName() + ")");
var folders = ownerFiles[i].getParents();
var folder = folders.next();
cells.getCell(i+2,2).setValue(folder);
}
}
function onOpen() {
SpreadsheetApp.getUi().createMenu('List')
.addItem('Public Files Owned by...', 'doGet')
.addToUi();
}
To run the script, reopen the spreadsheet after first saving the script, then click "List"->"Public Files Owned by...".
Something to bear in mind is that this is an inefficient script; if you have a lot of files stored in your Drive, this could take a long time to execute. In addition, it is currently written to accommodate up to 499 entries. (Increasing this maximum is simply a matter of raising the number for the 'B' column in the cells
declaration.) It is also currently written to output only the first parent folder if a file is contained in multiple folders.
-
I fully realise that this is an inefficient script; if anybody has any ideas for improving its efficiency, please do edit my post. I was also unable to debug the majority of the script due to time constraints, so I am not 100% sure this will work. Commented Nov 10, 2016 at 21:05
If you are admin you can use the Drige API with a service account impersonating that user.
-
-
You are right. Then, only those shared directly with you or those you have opened.– RiëlCommented Sep 5, 2015 at 21:00