Class Site

Site

An object representing a Google Site.

Methods

MethodReturn typeBrief description
addEditor(emailAddress)SiteAdds the given user to the list of editors for the Site.
addEditor(user)SiteAdds the given user to the list of editors for the Site.
addEditors(emailAddresses)SiteAdds the given array of users to the list of editors for the Site.
addOwner(email)SiteAdd a new owner to the website
addOwner(user)SiteAdd a new owner to the website
addViewer(emailAddress)SiteAdds the given user to the list of viewers for the Site.
addViewer(user)SiteAdds the given user to the list of viewers for the Site.
addViewers(emailAddresses)SiteAdds the given array of users to the list of viewers for the Site.
createAnnouncementsPage(title, name, html)PageCreate a new announcements page.
createFileCabinetPage(title, name, html)PageCreate a new file-cabinet page.
createListPage(title, name, html, columnNames)PageCreate a new list page.
createPageFromTemplate(title, name, template)PageCreate a new page from a template.
createWebPage(title, name, html)PageCreate a new web page.
getAllDescendants()Page[]Gets an array of descendant pages (direct and indirect), up to a limit of 200 pages.
getAllDescendants(options)Page[]Gets an array of descendant pages, with optional advanced arguments.
getChildByName(name)PageGets a particular child page.
getChildren()Page[]Gets an array of child pages, up to a limit of 200 pages.
getChildren(options)Page[]Gets an array of child pages, with optional advanced arguments.
getEditors()User[]Gets the list of editors for this Site.
getName()StringReturn the name of the site
getOwners()User[]Retrieves list of owners for the site
getSummary()StringReturn the summary of the web site
getTemplates()Page[]Returns all template pages.
getTheme()StringGets the theme of the site
getTitle()StringReturn the title of the site
getUrl()StringRetrieves the url of this Site.
getViewers()User[]Gets the list of viewers and commenters for this Site.
removeEditor(emailAddress)SiteRemoves the given user from the list of editors for the Site.
removeEditor(user)SiteRemoves the given user from the list of editors for the Site.
removeOwner(email)SiteRemoves owner from the site by user email
removeOwner(user)SiteRemoves owner from the site
removeViewer(emailAddress)SiteRemoves the given user from the list of viewers and commenters for the Site.
removeViewer(user)SiteRemoves the given user from the list of viewers and commenters for the Site.
search(query)Page[]Gets an array of descendant pages that match a search query, up to a limit of 200 pages.
search(query, options)Page[]Gets an array of descendant pages that match a search query, with optional advanced arguments.
setSummary(summary)SiteSet the summary of the web site
setTheme(theme)SiteSets the theme of the site
setTitle(title)SiteSet the title of the site

Detailed documentation

addEditor(emailAddress)

Adds the given user to the list of editors for the Site. If the user was already on the list of viewers, this method promotes the user out of the list of viewers.

Parameters

NameTypeDescription
emailAddressStringThe email address of the user to add.

Return

Site — This Site, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

addEditor(user)

Adds the given user to the list of editors for the Site. If the user was already on the list of viewers, this method promotes the user out of the list of viewers.

Parameters

NameTypeDescription
userUserA representation of the user to add.

Return

Site — This Site, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

addEditors(emailAddresses)

Adds the given array of users to the list of editors for the Site. If any of the users were already on the list of viewers, this method promotes them out of the list of viewers.

Parameters

NameTypeDescription
emailAddressesString[]An array of email addresses of the users to add.

Return

Site — This Site, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

addOwner(email)

Add a new owner to the website

var site = SitesApp.getSite("example.com", "mysite");
site.addOwner("eric@example.com");

Parameters

NameTypeDescription
emailStringThe email of the user to add as an owner

Return

Site — this site for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

addOwner(user)

Add a new owner to the website

var site = SitesApp.getSite("example.com", "mysite");
var currentUser = Session.getActiveUser();
site.addOwner(currentUser);

Parameters

NameTypeDescription
userUserThe user to add as an owner

Return

Site — this site for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

addViewer(emailAddress)

Adds the given user to the list of viewers for the Site. If the user was already on the list of editors, this method has no effect.

Parameters

NameTypeDescription
emailAddressStringThe email address of the user to add.

Return

Site — This Site, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

addViewer(user)

Adds the given user to the list of viewers for the Site. If the user was already on the list of editors, this method has no effect.

Parameters

NameTypeDescription
userUserA representation of the user to add.

Return

Site — This Site, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

addViewers(emailAddresses)

Adds the given array of users to the list of viewers for the Site. If any of the users were already on the list of editors, this method has no effect for them.

Parameters

NameTypeDescription
emailAddressesString[]An array of email addresses of the users to add.

Return

Site — This Site, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

createAnnouncementsPage(title, name, html)

Create a new announcements page. Note that a parent site or page cannot have more than 500 child pages.

// 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>");

Parameters

NameTypeDescription
titleStringthe page title
nameStringthe page name
htmlStringthe page content

Return

Page — the newly created Page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

createFileCabinetPage(title, name, html)

Create a new file-cabinet page. Note that a parent site or page cannot have more than 500 child pages.

// 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>");

Parameters

NameTypeDescription
titleStringthe page title
nameStringthe page name
htmlStringthe page content

Return

Page — The newly created Page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

createListPage(title, name, html, columnNames)

Create a new list page. Note that a parent site or page cannot have more than 500 child pages.

// 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" ]);

Parameters

NameTypeDescription
titleStringthe page title
nameStringthe page name
htmlStringthe page content
columnNamesString[]the column names used for the list

Return

Page — The newly created Page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

createPageFromTemplate(title, name, template)

Create a new page from a template. Note that a parent site or page cannot have more than 500 child pages.

// 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);

Parameters

NameTypeDescription
titleStringthe page title
nameStringthe page name
templatePagethe template page

Return

Page — the newly created Page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

createWebPage(title, name, html)

Create a new web page. Note that a parent site or page cannot have more than 500 child pages.

// 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>");

Parameters

NameTypeDescription
titleStringthe page title
nameStringthe page name
htmlStringthe page content

Return

Page — The newly created Page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getAllDescendants()

Gets an array of descendant pages (direct and indirect), up to a limit of 200 pages.

var site = SitesApp.getSite("example.com", "mysite");
var pages = site.getAllDescendants();

Return

Page[] — an array of direct and indirect child pages

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getAllDescendants(options)

Gets an array of descendant pages, with optional advanced arguments.

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());
}

Parameters

NameTypeDescription
optionsObjectJavaScript object fields defined in the Advanced Arguments section below

Advanced parameters

NameTypeDescription
typePageType[]only get pages of this type
startIntegerstart the results here
maxIntegerthe max number of results (default 200)
includeDraftsBooleanwhether to include draft pages (default false)
includeDeletedBooleanwhether to include deleted pages (default false)
searchStringonly return pages matching this query

Return

Page[] — an array of direct and indirect child pages of the given type

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getChildByName(name)

Gets a particular child page.

var site = SitesApp.getSite("example.com", "mysite");
var pages = site.getChildByName("childPage");

Parameters

NameTypeDescription
nameStringthe child page name

Return

Page — the child page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getChildren()

Gets an array of child pages, up to a limit of 200 pages.

var site = SitesApp.getSite("example.com", "mysite");
var pages = site.getChildren();

Return

Page[] — an array of direct child pages

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getChildren(options)

Gets an array of child pages, with optional advanced arguments.

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());
}

Parameters

NameTypeDescription
optionsObjectJavaScript object fields defined in the Advanced Arguments section below

Advanced parameters

NameTypeDescription
typePageType[]only get pages of this type
startIntegerstart the results here
maxIntegerthe max number of results (default 200)
includeDraftsBooleanwhether to include draft pages (default false)
includeDeletedBooleanwhether to include deleted pages (default false)
searchStringonly return pages matching this query

Return

Page[] — an array of direct child pages of the given type

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getEditors()

Gets the list of editors for this Site. If the user who executes the script does not have edit access to the Site, this method throws an exception.

Return

User[] — An array of users with edit permission.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getName()

Return the name of the site

var name = SitesApp.getSite('example.com', 'mysite').getName();

Return

String — the name of this Site instance

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getOwners()

Retrieves list of owners for the site

var owners = SitesApp.getSite('example.com', 'mysite').getOwners();
for(var i in owners) {
  Logger.log(owners[i].getEmail())
}

Return

User[] — an array containing User instances representing owners

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getSummary()

Return the summary of the web site

var summary = SitesApp.getSite('example.com', 'mysite').getSummary();

Return

String — the summary of this site

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getTemplates()

Returns all template pages.

var templates = SitesApp.getSite('example.com', 'mysite').getTemplates();
for(var i in templates) {
  Logger.log(templates[i].getName())
}

Return

Page[] — an array containing Page instances representing templates

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getTheme()

Gets the theme of the site

var theme = SitesApp.getSite('example.com', 'mysite').getTheme();

Return

String — the theme of this site

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getTitle()

Return the title of the site

var title = SitesApp.getSite('example.com', 'mysite').getTitle();

Return

String — the title of this site

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getUrl()

Retrieves the url of this Site.

var url = SitesApp.getSite('example.com', 'mysite').getUrl();

Return

String — the url of this Site instance

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getViewers()

Gets the list of viewers and commenters for this Site. If the user who executes the script does not have edit access to the Site, this method throws an exception.

Return

User[] — An array of users with view or comment permission.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

removeEditor(emailAddress)

Removes the given user from the list of editors for the Site. This method does not block users from accessing the Site if they belong to a class of users who have general access—for example, if the Site is shared with the user's entire domain.

Parameters

NameTypeDescription
emailAddressStringThe email address of the user to remove.

Return

Site — This Site, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

removeEditor(user)

Removes the given user from the list of editors for the Site. This method does not block users from accessing the Site if they belong to a class of users who have general access—for example, if the Site is shared with the user's entire domain.

Parameters

NameTypeDescription
userUserA representation of the user to remove.

Return

Site — This Site, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

removeOwner(email)

Removes owner from the site by user email

// This snippet removes the user with the given email from the owners list
var site = SitesApp.getSite('example.com', 'mysite');
site.removeOwner("eric@example.com");

Parameters

NameTypeDescription
emailStringThe email of the user to remove from the owners

Return

Site — the site instance for method chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

removeOwner(user)

Removes owner from the site

// This snippet removes the current user from the list of owners
var site = SitesApp.getSite('example.com', 'mysite');
site.removeOwner(Session.getActiveUser());

Parameters

NameTypeDescription
userUserA user to remove from the list of owners

Return

Site — the site instance for method chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

removeViewer(emailAddress)

Removes the given user from the list of viewers and commenters for the Site. This method has no effect if the user is an editor, not a viewer or commenter. This method also does not block users from accessing the Site if they belong to a class of users who have general access—for example, if the Site is shared with the user's entire domain.

Parameters

NameTypeDescription
emailAddressStringThe email address of the user to remove.

Return

Site — This Site for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

removeViewer(user)

Removes the given user from the list of viewers and commenters for the Site. This method has no effect if the user is an editor, not a viewer. This method also does not block users from accessing the Site if they belong to a class of users who have general access—for example, if the Site is shared with the user's entire domain.

Parameters

NameTypeDescription
userUserA representation of the user to remove.

Return

Site — This Site for chaining.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

search(query)

Gets an array of descendant pages that match a search query, up to a limit of 200 pages.

var site = SitesApp.getSite("example.com", "mysite");
var matches = site.search("targetText");

for(var i in matches) {
  Logger.log(matches[i].getName());
}

Parameters

NameTypeDescription
queryStringthe full text search query to match

Return

Page[] — an array of direct and indirect child pages of the given type

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

search(query, options)

Gets an array of descendant pages that match a search query, with optional advanced arguments.

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());
}

Parameters

NameTypeDescription
queryStringthe full text search query to match
optionsObjectJavaScript object fields defined in the Advanced Arguments section below

Advanced parameters

NameTypeDescription
typePageType[]only get pages of this type
startIntegerstart the results here
maxIntegerthe max number of results (default 200)
includeDraftsBooleanwhether to include draft pages (default false)
includeDeletedBooleanwhether to include deleted pages (default false)

Return

Page[] — an array of direct and indirect child pages of the given type

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

setSummary(summary)

Set the summary of the web site

var site = SitesApp.getSite("example.com", "mysite");
// All of the setter methods return the site instance so setters
// can be chained
site.setTitle("My Site")
    .setSummary("This is my site")
    .setTheme("simple");

Parameters

NameTypeDescription
summaryStringA string summary describing the site

Return

Site — the site for method chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

setTheme(theme)

Sets the theme of the site

Theme must be a valid theme string. For an exhaustive list, write a test method and pass an invalid value to setTheme(). The script will throw a Service error and return an exhaustive list of available themes. The list of available themes is also available under Manage Site->Themes. Theme name strings are generally the same as the theme name on the Themes page in lower cases with spaces and special characters removed. For example, the string for "Terra: Water" would be "terrawater".

var site = SitesApp.getSite("example.com", "mysite");
// All of the setter methods return the site instance so setters
// can be chained
site.setTitle("My Site")
    .setSummary("This is my site")
    .setTheme("simple");

Parameters

NameTypeDescription
themeStringa string name for the theme to set for this Site

Return

Site — the site for method chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

setTitle(title)

Set the title of the site

var site = SitesApp.getSite("example.com", "mysite");
// All of the setter methods return the site instance so setters
// can be chained
site.setTitle("My Site")
    .setSummary("This is my site")
    .setTheme("simple");

Parameters

NameTypeDescription
titleStringthe new title of the site

Return

Site — the site for method chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

Deprecated methods





















发送以下问题的反馈:

此网页
Apps Script
Apps Script
需要帮助?请访问我们的支持页面