Class SitesApp

SitesApp

Create and access Google Sites.

Properties

PropertyTypeDescription
AttachmentTypeAttachmentType
PageTypePageType

Methods

MethodReturn typeBrief description
copySite(domain, name, title, summary, site)SiteCreates a new Site by copying an existing Site.
createSite(domain, name, title, summary)SiteCreates a new Site.
getActivePage()PageReturns the active page, if the script is hosted in a container, or null otherwise.
getActiveSite()SiteReturns the active container, if the script is hosted in a container, or null otherwise.
getAllSites(domain)Site[]Retrieves first page of Sites belonging to this domain.
getAllSites(domain, start, max)Site[]Retrieves all Sites belonging to this domain.
getPageByUrl(url)PageRetrieves a Page by url.
getSite(name)SiteRetrieves a Site for the given Google Site, if the user is a consumer who does not have a hosted domain.
getSite(domain, name)SiteRetrieves a Site for the given Google Site.
getSiteByUrl(url)SiteRetrieves a Site by url.
getSites()Site[]Retrieves first page of Sites for a user, if the user is a consumer who does not have a hosted domain.
getSites(start, max)Site[]Retrieves Sites for a user between the given bounds if the user is a consumer who does not have a hosted domain.
getSites(domain)Site[]Retrieves first page of Sites belonging to this user in this domain.
getSites(domain, start, max)Site[]Retrieves all Sites belonging to this user in this domain for the given range given.

Detailed documentation

copySite(domain, name, title, summary, site)

Creates a new Site by copying an existing Site.

Warning: Copying a site takes time, from seconds to possibly many minutes, depending on the size of the site. Although the method returns right away, the copy is still going on in the background, and not all pages in the copied site will be immediately available. This method can also be used to instantiate a new site based on a given template.

// This creates a site. Note that this only works for G Suite domains.
// There is no version of this API for consumer accounts.
var site = SitesApp.createSite("example.com",
                               "homepage",
                               "My Home Page",
                               "This is a new site I created!");

var siteCopy = SitesApp.copySite("example.com",
                                 "homepage-clone",
                                 "Cloned Home Page",
                                 "Begun, these clone wars have.",
                                 site);

Parameters

NameTypeDescription
domainStringThe G Suite hosted domain (e.g. example.com)
nameStringThe webspace name found in the URL (e.g. mySite)
titleStringThe title of the site
summaryStringThe description of the site
siteSiteThe Site to copy from. This can either be a site or a template. If the parameter is an existing site then the entire contents of the site will be copied. If the given Site is a template, then a new Site is created based on that template.

Return

Site — The site that was copied. Note that the copy is asynchronous, and the copy operation may still be ongoing even though a reference to the site has been returned.

Authorization

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

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

createSite(domain, name, title, summary)

Creates a new Site.

// This creates a site. Note that this only works for G Suite domains.
// There is no version of this API for consumer accounts.
var site = SitesApp.createSite("example.com",
                               "homepage",
                               "My Home Page",
                               "This is a new site I created!");

Parameters

NameTypeDescription
domainStringThe G Suite hosted domain (e.g. example.com)
nameStringthe path name found in the URL (e.g. mySite)
titleStringThe title of the site
summaryStringThe description of the site

Return

Site — The created site

Authorization

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

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

getActivePage()

Returns the active page, if the script is hosted in a container, or null otherwise.

var site = SitesApp.getActivePage();

Return

Page — the active container if it is a sites page

Authorization

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

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

getActiveSite()

Returns the active container, if the script is hosted in a container, or null otherwise.

var site = SitesApp.getActiveSite();

Return

Site — the active container if it is a site

Authorization

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

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

getAllSites(domain)

Retrieves first page of Sites belonging to this domain.

// This writes the first page of sites belonging to a G Suite
// domain to the log.
var sites = SitesApp.getAllSites("example.com");
for(var i in sites) {
  Logger.log(sites[i].getUrl());
}

Parameters

NameTypeDescription
domainStringThe G Suite hosted domain (e.g. example.com)

Return

Site[] — an array of sites belonging to the domain

Authorization

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

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

getAllSites(domain, start, max)

Retrieves all Sites belonging to this domain.

// This writes the a list of sites in domain example.com to the log.
var pageStart = 0;
var pageSize = 50;
while (true) {
  Logger.log("Loading sites starting at %s", pageStart);
  var sites = SitesApp.getAllSites("example.com", pageStart, pageSize);
  if (sites.length == 0) {
    break;
  }
  Logger.log("Got %s sites back", sites.length);
  pageStart += sites.length;
  for(var i in sites) {
    Logger.log("Found site: %s", sites[i].getUrl());
  }
}

Parameters

NameTypeDescription
domainStringThe G Suite hosted domain (e.g. example.com)
startIntegerthe index of the first site to return
maxIntegerthe maximum number of results to return

Return

Site[] — an array of sites belonging to the domain

Authorization

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

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

getPageByUrl(url)

Retrieves a Page by url.

// This snippet retrieves the page at the given URL.
// Returns null if the page does not exist or if the URL given is invalid.
var page = SitesApp.getPageByUrl(
                    "https://sites.google.com/site/demositeappsscript/mylistpage");
Logger.log(page.getName());

Parameters

NameTypeDescription
urlStringthe public url

Return

Page — a Page instance corresponding to the page at the URL or null if the page does not exist.

Authorization

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

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

getSite(name)

Retrieves a Site for the given Google Site, if the user is a consumer who does not have a hosted domain.

// Returns a Site instance
var site = SitesApp.getSite('mysite');

Parameters

NameTypeDescription
nameStringThe webspace name found in the URL (e.g. mySite)

Return

Site — A Site instance corresponding to a consumer site

Authorization

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

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

getSite(domain, name)

Retrieves a Site for the given Google Site.

// Returns a Site instance
var site = SitesApp.getSite('example.com', 'mysite');

Parameters

NameTypeDescription
domainStringThe G Suite hosted domain (e.g. example.com)
nameStringThe webspace name found in the URL (e.g. mySite)

Return

Site — A Site instance corresponding to a hosted domain

Authorization

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

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

getSiteByUrl(url)

Retrieves a Site by url.

// This snippet retrieves the site at the given URL
// Throws an Invalid argument exception if the site does not exist or if
// the URL given is invalid
var site = SitesApp.getSiteByUrl("https://sites.google.com/site/demosite");
Logger.log(site.getName());

Parameters

NameTypeDescription
urlStringthe public url

Return

Site — a Site found at the given URL

Authorization

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

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

getSites()

Retrieves first page of Sites for a user, if the user is a consumer who does not have a hosted domain.

// This writes the first page of sites owned by the user running
// the script to the log.
var sites = SitesApp.getSites();
for(var i in sites) {
  Logger.log(sites[i].getUrl());
}

Return

Site[] — An array of sites beloning to the user running the script

Authorization

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

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

getSites(start, max)

Retrieves Sites for a user between the given bounds if the user is a consumer who does not have a hosted domain.

var sites = SitesApp.getSites(25, 50);
for(var i in sites) {
  Logger.log(sites[i].getUrl());
}

Parameters

NameTypeDescription
startIntegerthe index of the first site to return
maxIntegerthe maximum number of results to return

Return

Site[] — an array of all the sites owned for a user

Authorization

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

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

getSites(domain)

Retrieves first page of Sites belonging to this user in this domain.

// This writes the first page of sites owned by the user running
// the script to the log.
var sites = SitesApp.getSites("example.com");
for(var i in sites) {
  Logger.log(sites[i].getUrl());
}

Parameters

NameTypeDescription
domainStringThe G Suite hosted domain (e.g. example.com)

Return

Site[] — An array of sites beloning to the user running the script

Authorization

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

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

getSites(domain, start, max)

Retrieves all Sites belonging to this user in this domain for the given range given.

// This writes the a list of sites owned by the user running
// the script in positions bounded by the start and max values to the log.
var sites = SitesApp.getSites("example.com", 25, 50);
for(var i in sites) {
  Logger.log(sites[i].getUrl());
}

Parameters

NameTypeDescription
domainStringThe G Suite hosted domain (e.g. example.com)
startIntegerthe index of the first site to return
maxIntegerthe maximum number of results to return

Return

Site[] — an array of sites belonging to the user

Authorization

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

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

发送以下问题的反馈:

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