Pages

Monday, March 9, 2015

Control your Google Sites from Apps Script

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.
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. Heres 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", "Well be the divisional champs this year!");

// create a page for each member of the team
var webpage = site.createWebPage("Jimmys Page", "JimmysPage", "Welcome to Jimmys site");

// create a page for team announcements
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);

Its that easy! Check out the documentation and get started building your scripts.

Of course, if you decide that youd 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

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.