Google 协作平台上的页面。
方法
详细文档
addColumn(name)
向列表中添加新列。仅适用于列表页面。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildByName("listpage"); // Only valid on List pages. Check for the type like so: // if(page.getPageType() == SitesApp.PageType.LIST_PAGE)) var columns = page.addColumn("new-column");
参数
名称 | 类型 | 说明 |
---|---|---|
name | String | 新列的名称 |
返回
Column
- 新创建的列
抛出
Error
- 适用于未列出的网页
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
addHostedAttachment(blob)
向页面添加附件。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; // Create a new blob and attach it. Many useful functions also return // blobs file uploads, URLFetch var blob = Utilities.newBlob("Here is some data", "text/plain", "data.txt"); // Note that the filename must be unique or this call will fail page.addHostedAttachment(blob);
参数
名称 | 类型 | 说明 |
---|---|---|
blob | BlobSource | 附件的数据 |
返回
Attachment
- 新创建的连接
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
addHostedAttachment(blob, description)
向页面添加附件。此版本的函数提供说明。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; // Create a new blob and attach it. Many useful: functions also return // blobs file uploads, URLFetch var blob = Utilities.newBlob("Here is some data", "text/plain", "data.txt"); // Note that the filename must be unique or this call will fail page.addHostedAttachment(blob, "Some newly created data");
参数
名称 | 类型 | 说明 |
---|---|---|
blob | BlobSource | 附件的数据 |
description | String | 附件说明 |
返回
Attachment
- 新创建的连接
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
addListItem(values)
将列表项添加到列表中。仅适用于列表页面。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildByName("listpage"); // Only valid on List pages. Check for the type like so: // if(page.getPageType() == SitesApp.PageType.LIST_PAGE)) // Returns only one item page.addListItem([ "John", "Smith", "123 Main St"]);
参数
名称 | 类型 | 说明 |
---|---|---|
values | String[] | 每列的值 |
返回
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
addWebAttachment(title, description, url)
将网络附件添加到页面中。仅适用于文件箱式页面。
网络附件是链接,实际上并非由 Google 协作平台托管。
var site = SitesApp.getSite("example.com", "mysite"); // fetch the child - this must be a File Cabinet page // to programmatically check this, do a comparison: // if(page.getPageType() == SitesApp.PageType.FILE_CABINET_PAGE) var page = site.getChildByName("files"); page.addWebAttachment("Google Robots file", "This is Google's robots.txt file", "http://www.google.com/robots.txt");
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 附件的标题 |
description | String | 附件说明 |
url | String | 附加的文件的网址 |
返回
Attachment
- 新创建的连接
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
createAnnouncement(title, html)
为此页面创建通知。仅对公告页面有效。
var site = SitesApp.getSite("example.com", "mysite"); // This snippet will only work with announcement pages - this is different // from a page that is an annoucement (individual announcements). To check // if this method can be called: // if(page.getPageType() == SitesApp.PageType.ANNOUNCEMENTS_PAGE)) var page = site.getChildByName("news"); page.createAnnouncement("Breaking news!", "<h1>Apps Script rocks!</h1>");
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 网页标题 |
html | String | 网页内容 |
返回
Page
- 新创建的通知
抛出
Error
- 适用于非公告页
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
createAnnouncement(title, html, asDraft)
为此页面创建通知。仅对公告页面有效。
var site = SitesApp.getSite("example.com", "mysite"); // This snippet will only work with announcement pages - this is different // from a page that is an annoucement (individual announcements). To check // if this method can be called: // if(page.getPageType() == SitesApp.PageType.ANNOUNCEMENTS_PAGE)) var page = site.getChildByName("news"); page.createAnnouncement("Breaking news!", "<h1>Apps Script rocks!</h1>", true);
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 网页标题 |
html | String | 网页内容 |
asDraft | Boolean | 是否将通知设为草稿 |
返回
Page
- 新创建的通知
抛出
Error
- 适用于非公告页
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
createAnnouncementsPage(title, name, html)
创建新的公告页面。请注意,父网站或子网页的子页面不能超过 500 个。
// This method can be called from both a Site instance // as well as a Page instance var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; site.createAnnouncementsPage("New Announcement", "new-announcement", "<h1>Your announcement goes here</h1>"); page.createAnnouncementsPage("New Announcement", "new-announcement-child", "<h1>Your announcement goes here</h1>");
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 网页标题 |
name | String | 网页名称 |
html | String | 网页内容 |
返回
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
createFileCabinetPage(title, name, html)
创建新的文件箱式页面。请注意,父级网站或页面的子页面不能超过 500 个。
// This method can be called from either a site or a page. var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; site.createFileCabinetPage("New File Cabinet", "new-file-cabinet", "<h1>Your HTML here</h1>"); page.createFileCabinetPage("New File Cabinet", "new-file-cabinet-child", "<h1>Your HTML here</h1>");
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 网页标题 |
name | String | 网页名称 |
html | String | 网页内容 |
返回
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
createListPage(title, name, html, columnNames)
创建新的列表页面。请注意,父网站或子网页的子页面不能超过 500 个。
// This method can be called from either a site or a page. var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; site.createListPage("New List Page", "new-list-page", "<h1>Your List Page HTML here</h1>", [ "col1", "col2" ]); page.createListPage("New List Page", "new-list-page-child", "<h1>Your List Page HTML here</h1>", [ "col1", "col2" ]);
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 网页标题 |
name | String | 网页名称 |
html | String | 网页内容 |
columnNames | String[] | 用于列表的列名称 |
返回
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
createPageFromTemplate(title, name, template)
通过模板创建新页面。请注意,父网站或子网页的子页面不能超过 500 个。
// This method can be called from either a site or a page. var site = SitesApp.getSite("example.com", "mysite"); var template = site.getTemplates()[0]; // If an invalid template is passed, this will throw an "Invalid Argument" error. site.createPageFromTemplate("ClonedPage", "cloned-page", template);
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 网页标题 |
name | String | 网页名称 |
template | Page | 模板页面 |
返回
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
createWebPage(title, name, html)
创建新网页。请注意,父网站或子网页的子页面不能超过 500 个。
// This method can be called from either a site or a page. var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; site.createAnnouncementsPage("New Announcement", "new-announcement", "<h1>Your announcement goes here</h1>"); page.createAnnouncementsPage("New Announcement", "new-announcement-child", "<h1>Your announcement goes here</h1>");
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 网页标题 |
name | String | 网页名称 |
html | String | 网页内容 |
返回
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
deletePage()
删除此页面。
var site = SitesApp.getSite("example.com", "mysite"); // Delete ALL the pages! var pages = site.getAllDescendants(); for(var i in pages) { pages[i].deletePage(); }
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getAllDescendants()
getAllDescendants(options)
获取后代网页数组,其中包含高级高级参数(可选)。
var site = SitesApp.getSite("example.com", "mysite"); var descendants = site.getAllDescendants({ type: SitesApp.PageType.WEB_PAGE, start: 0, max: 25, includeDrafts: false, includeDeleted: true, search: "target" }); for(var i in descendants) { Logger.log(descendants[i].getName()); }
参数
名称 | 类型 | 说明 |
---|---|---|
options | Object | 下面的“高级参数”部分定义了 JavaScript 对象字段 |
高级参数
名称 | 类型 | 说明 |
---|---|---|
type | PageType[] | 仅获取此类网页 |
start | Integer | 从此处开始结果 |
max | Integer | 结果数上限(默认为 200 条) |
includeDrafts | Boolean | 是否要包含草稿页(默认为 false) |
includeDeleted | Boolean | 是否要包含已删除的页面(默认为 false) |
search | String | 仅返回与此查询匹配的页面 |
返回
Page[]
- 一组给定类型的直接和间接子页面
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getAnnouncements()
获取此页面上的公告。仅对公告页面有效。
var site = SitesApp.getSite("example.com", "mysite"); // This snippet will only work with announcement pages - this is different // from a page that is an annoucement (individual announcements). To check // if this method can be called: // if(page.getPageType() == SitesApp.PageType.ANNOUNCEMENTS_PAGE)) var page = site.getChildByName("news"); var announcements = page.getAnnouncements(); for(var i in announcements) { Logger.log(announcements[i].getHtmlContent()); }
返回
Page[]
- 公告数组
抛出
Error
- 适用于非公告页
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getAnnouncements(optOptions)
获取此页面上的公告。仅对公告页面有效。
var site = SitesApp.getSite("example.com", "mysite"); // This snippet will only work with announcement pages - this is different // from a page that is an annoucement (individual announcements). To check // if this method can be called: // if(page.getPageType() == SitesApp.PageType.ANNOUNCEMENTS_PAGE)) var page = site.getChildByName("news"); var announcements = page.getAnnouncements({ start: 0, max: 20, includeDrafts: false, includeDeleted: false, search: "Breaking" }); for(var i in announcements) { Logger.log(announcements[i].getHtmlContent()); }
参数
名称 | 类型 | 说明 |
---|---|---|
optOptions | Object | 包含高级参数的 JavaScript 对象 |
高级参数
名称 | 类型 | 说明 |
---|---|---|
start | Integer | 结果的起始索引 |
max | Integer | 要返回的结果数上限,默认值为 200, |
includeDrafts | Boolean | 是否要包含草稿页(默认为 false) |
includeDeleted | Boolean | 是否要包含已删除的页面(默认为 false) |
search | String | 仅返回与此查询匹配的页面 |
返回
Page[]
- 公告数组
抛出
Error
- 适用于非公告页
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getAttachments()
获取此页面的附件。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; var attachments = page.getAttachments(); for(var i in attachments) { Logger.log(attachments[i].getTitle()); }
返回
Attachment[]
- 附件数组
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getAttachments(optOptions)
获取此页面的附件。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; // This returns only one attachment var attachments = page.getAttachments({ start: 0, max: 1}); for(var i in attachments) { Logger.log(attachments[i].getTitle()); }
参数
名称 | 类型 | 说明 |
---|---|---|
optOptions | Object | 包含可选参数的 JavaScript 对象 |
高级参数
名称 | 类型 | 说明 |
---|---|---|
start | Integer | 第一个开始返回附件的索引 |
max | Integer | 要返回的结果数上限,默认值为 200, |
返回
Attachment[]
- 附件数组
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getAuthors()
获取网页作者的电子邮件
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; var authors = page.getAuthors(); for(var i in authors) { Logger.log(authors[i]); }
返回
String[]
- 作者电子邮件地址数组
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getChildByName(name)
getChildren()
getChildren(options)
获取包含可选高级参数的子页面数组。
var site = SitesApp.getSite("example.com", "mysite"); var childPages = site.getChildren({ type: SitesApp.PageType.WEB_PAGE, start: 0, max: 25, includeDrafts: false, includeDeleted: true, search: "target" }); for(var i in childPages) { Logger.log(childPages[i].getName()); }
参数
名称 | 类型 | 说明 |
---|---|---|
options | Object | 下面的“高级参数”部分定义了 JavaScript 对象字段 |
高级参数
名称 | 类型 | 说明 |
---|---|---|
type | PageType[] | 仅获取此类网页 |
start | Integer | 从此处开始结果 |
max | Integer | 结果数上限(默认为 200 条) |
includeDrafts | Boolean | 是否要包含草稿页(默认为 false) |
includeDeleted | Boolean | 是否要包含已删除的页面(默认为 false) |
search | String | 仅返回与此查询匹配的页面 |
返回
Page[]
- 给定类型的直接子页面数组
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getColumns()
获取列表列。仅适用于列表页面。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildByName("listpage"); // Only valid on List pages. Check for the type like so: // if(page.getPageType() == SitesApp.PageType.LIST_PAGE)) var columns = page.getColumns(); for(var i in columns) { Logger.log(columns[i].getName()); }
返回
抛出
Error
- 适用于未列出的网页
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getDatePublished()
返回此页面的首次发布日期。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; Logger.log(page.getName() + " was published " + page.getDatePublished());
返回
Date
- 原始发布日期
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getHtmlContent()
获取网页的 HTML 内容。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; Logger.log(page.getHtmlContent());
返回
String
- HTML 内容
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getIsDraft()
返回页面是否处于草稿模式。仅适用于公告。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; Logger.log("Is this Announcement Page a draft?", page.getIsDraft());
返回
Boolean
- 网页是否处于草稿模式
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getLastEdited()
返回上次修改日期,其中仅包含内容修改日期。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; Logger.log(page.getName() + " was last updated " + page.getLastEdited());
返回
Date
- 上次更新网页的日期,仅包括内容修改
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getLastUpdated()
返回上次更新日期,包括移动等非内容更改。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; Logger.log(page.getName() + " was last updated " + page.getLastUpdated());
返回
Date
- 网页上次内容更新的日期
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getListItems()
获取列表项。仅适用于列表页面。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildByName("listpage"); // Only valid on List pages. Check for the type like so: // if(page.getPageType() == SitesApp.PageType.LIST_PAGE)) var items = page.getListItems(); for(var i in items) { Logger.log(items[i].getValueByName("Status")); }
返回
ListItem[]
- 一组 ListItem
实例
抛出
Error
- 适用于未列出的网页
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getListItems(optOptions)
获取列表项。仅适用于列表页面。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildByName("listpage"); // Only valid on List pages. Check for the type like so: // if(page.getPageType() == SitesApp.PageType.LIST_PAGE)) // Returns only one item var items = page.getListItems({ start:0, max: 1 }); for(var i in items) { Logger.log(items[i].getValueByName("Status")); }
参数
名称 | 类型 | 说明 |
---|---|---|
optOptions | Object | 可选参数的 JavaScript 对象 |
高级参数
名称 | 类型 | 说明 |
---|---|---|
start | Integer | 从其开始迭代的第一个索引 |
max | Integer | 要返回的结果数上限,默认值为 200, |
返回
ListItem[]
- 一组 ListItem
实例
抛出
Error
- 适用于未列出的网页
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getName()
返回相应页面的名称。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; Logger.log(page.getName());
返回
String
- 此页面的名称
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getPageType()
将此网页的类型作为 SitesApp.PageType 枚举返回。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; var pageType = page.getPageType(); if(pageType == SitesApp.PageType.WEB_PAGE) { Logger.log(page.getName() + " is a Web Page"); }
返回
PageType
- 用于指示这是网页、列表、公告还是文件箱式页面的 PageType 枚举
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getParent()
getTextContent()
返回纯文本页面内容。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; Logger.log(page.getName() + " content: " + page.getTextContent());
返回
String
- 网页的纯文本内容
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getTitle()
返回网页的标题。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; Logger.log(page.getTitle());
返回
String
- 此页面的标题
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
getUrl()
获取网页的网址。
var site = SitesApp.getSite("example.com", "mysite"); var page = site.getChildren()[0]; Logger.log(page.getUrl());
返回
String
- 网页的网址
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
isDeleted()
isTemplate()
返回此页面是否为可复制模板。
var site = SitesApp.getSite("example.com", "mysite"); var firstTemplate = site.getTemplates()[0]; if(firstTemplate.isTemplate()) { Logger.log("This will always return true"); }
返回
Boolean
- 此页面是否为模板
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
publishAsTemplate(name)
search(query)
获取一个与搜索查询匹配的后代网页数组(上限为 200 个网页)。
var site = SitesApp.getSite("example.com", "mysite"); var matches = site.search("targetText"); for(var i in matches) { Logger.log(matches[i].getName()); }
参数
名称 | 类型 | 说明 |
---|---|---|
query | String | 要匹配的全文搜索查询 |
返回
Page[]
- 一组给定类型的直接和间接子页面
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds
search(query, options)
获取一个与搜索查询相匹配的后代网页数组,其中含有可选的高级参数。
var site = SitesApp.getSite("example.com", "mysite"); var childPages = site.getChildren({ type: SitesApp.PageType.WEB_PAGE, start: 0, max: 25, includeDrafts: false, includeDeleted: true, search: "target" }); for(var i in childPages) { Logger.log(childPages[i].getName()); }
参数
名称 | 类型 | 说明 |
---|---|---|
query | String | 要匹配的全文搜索查询 |
options | Object | 下面的“高级参数”部分定义了 JavaScript 对象字段 |
高级参数
名称 | 类型 | 说明 |
---|---|---|
type | PageType[] | 仅获取此类网页 |
start | Integer | 从此处开始结果 |
max | Integer | 结果数上限(默认为 200 条) |
includeDrafts | Boolean | 是否要包含草稿页(默认为 false) |
includeDeleted | Boolean | 是否要包含已删除的页面(默认为 false) |
返回
Page[]
- 一组给定类型的直接和间接子页面
授权
使用此方法的脚本需要通过以下一个或多个范围进行授权:
-
https://sites.google.com/feeds