How to get get the "shareable link" of a Google Drive file via Google Apps Script?
How about following sample script? In this sample, it retrieves shared URLs of images in a specific folder.
Sample Script :
function myFunction() {
var folderId = "### Specific folder ID ###";
var files = DriveApp.getFolderById(folderId).getFiles();
var result = [];
while (files.hasNext()) {
var file = files.next();
file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
var temp = {
file_name: file.getName(),
url: "http://drive.google.com/uc?export=view&id=" + file.getId(),
};
result.push(temp);
};
Logger.log(JSON.stringify(result))
}
Result :
[
{
"file_name": "filename1",
"url": "http://drive.google.com/uc?export=view&id=### file ID 1###"
},
{
"file_name": "filename2",
"url": "http://drive.google.com/uc?export=view&id=### file ID 2###"
}
]
Flow :
Retrieve files in a folder which was set by
folderId
.Modify the permission of files. By this, users who don't login can also see the files. Only users who know the URLs can see them.
Retrieve filename and file ID. And Retrieve file URLs using file ID. The URLs are the direct links for images.
In this sample, folders in the folder cannot be checked. If you also want to check folders in the folder which was set by
folderId
, please tell me.
If I misunderstand your question, I'm sorry.