这是我的代码。基本上,我正在创建一个对象,它的一些属性是由实例化对象后需要运行的函数设置的。我正在 Google Scripts 代码编辑器中开发它,它运行时没有错误,但实际上并没有做任何事情。
此函数由时间触发器定期调用
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)
}