Control your Google Sites from Apps Script
February 10, 2010
Last August we announced Google Apps Script, which allows you to automate many of the features of Google Apps using server-side scripts. Scripts can work with contacts, calendars, spreadsheets, mail and even call SOAP and REST web services, all using standard JavaScript. We just launched additional support for creating and accessing Google Sites using the new SitesApp Service.
// create a site, given the domain, site URL, site title and summary
Ryan Boyd
Henry Lau, on the Google Apps Script team, has written a great tutorial on Creating a Soccer Club Homepage. In short, his script pulls upcoming Soccer matches from Google Calendar, creates a Google Site about the team and adds the Soccer team from Contacts as collaborators. Here's some snippets of the code.
// create a site, given the domain, site URL, site title and summary
var site = SitesApp.createSite("example.com", "rover", "Team Rover", "We'll be the divisional champs this year!");
// create a page for each member of the team
var webpage = site.createWebPage("Jimmy's Page", "JimmysPage", "Welcome to Jimmy's site");
var webpage = site.createWebPage("Jimmy's Page", "JimmysPage", "Welcome to Jimmy's site");
// create a page for team announcements
var annPage = site.createAnnouncementsPage("Team Announcements", "Announcements", "New announcements for the team will be posted here.");
var annPage = site.createAnnouncementsPage("Team Announcements", "Announcements", "New announcements for the team will be posted here.");
// given one of the Google Calendar events, create an announcement
var message = "There will be a soccer match from " + event.getStartTime() + " until " + event.getEndTime() + "!";
site.createAnnouncement("Soccer Match #1", message, annPage);
site.createAnnouncement("Soccer Match #1", message, annPage);
It's that easy! Check out the documentation and get started building your scripts.
Of course, if you decide that you'd rather create Google Sites via a REST interface, the recently-announced enhancements to the Sites Data API will allow you to write code in your language of choice to create and manage sites.
Ryan Boyd
Developer Relations - Google Apps