これが私のコードです。基本的に、私はオブジェクトを作成しています。その属性の一部は、オブジェクトをインスタンス化したときに実行する必要のある関数によって設定されます。私はこれをGoogleScriptsコードエディタで開発しており、バグなしで実行されますが、実際には何もしません。
この関数は、タイムトリガーによって定期的に呼び出されます
function addFoldersToSites(){
//DriveObject class, has a folder id and page url, and uses those to get attachments
function DriveObject(folder_id,page_url) {
this.folder_id = folder_id
this.page_url = page_url
this.files = setFiles
this.page = setPage
this.attachments = setAttachments
}
function setFiles(){return DocsList.getFolderById(this.folder_id).getFiles();}
function setPage(){return SitesApp.getPageByUrl(this.page_url);}
function setAttachments(){return this.page.getAttachments();}
//instantiate drive objects
//if you want to add drive things to new site pages, this is where you do it
//*************************************************************************
var engpage = new DriveObject('0B6esS6X9k9LvWWFfc1oyN0VfeTg','https://sites.google.com/a/drawbrid.ge/resources/engineering/files');
var productpage = new DriveObject('0B6esS6X9k9LveUI0dmxxLWplaTA','https://sites.google.com/a/drawbrid.ge/resources/engineering/files');
var adminpage= new DriveObject('0B6esS6X9k9LvVUVDUlBWWWhJcDg','https://sites.google.com/a/drawbrid.ge/resources/home/files');
var genonboarding = new DriveObject('0B6esS6X9k9LvbjRtanE4eGNkdlE','https://sites.google.com/a/drawbrid.ge/resources/home/general-onboarding');
var salespage= new DriveObject('0B6esS6X9k9LvQ2JJN0pCblNyME0','https://sites.google.com/a/drawbrid.ge/resources/sales/files');
var researchpage = new DriveObject('0B6esS6X9k9LvM1RKeHVXRkNBZ1k','https://sites.google.com/a/drawbrid.ge/resources/market-research');
//function that iterates through folder files and puts them in the google site frame
function showFolderInSite(attachments, page, files) {
var attachments = attachments
var page = page
var files = files
for (i in attachments) {
attachments[i].deleteAttachment();
}
for (i in files) {
page.addWebAttachment(files[i].getName(), '', files[i].getUrl());
}
}
//run functions
showFolderInSite(engpage.attachments,engpage.page,engpage.files)
showFolderInSite(productpage.attachments,productpage.page,productpage.files)
showFolderInSite(adminpage.attachments,adminpage.page,adminpage.files)
showFolderInSite(genonboarding.attachments,genonboarding.page,genonboarding.files)
showFolderInSite(salespage.attachments,salespage.page,salespage.files)
showFolderInSite(researchpage.attachments,researchpage.page,researchpage.files)
}