Google Apps Script

What the heck is it?

Presented by LB Corney / @lb_corney

Google Products

    Google has provided some pretty awesome tools:

  • Google Calendar, Gmail, Contacts.
  • Google Drive with Sheets (spreadsheets), Docs (word processing).
  • Google Slides (PowerPoint?)
  • Google Drawings (best tool ever for app prototyping!)
  • Picassa images, Charts, etc....

What is Google Apps Script?

Google Apps Script is a JavaScript cloud scripting language that provides easy ways to automate tasks across Google products and third party services and build web applications.

Huh? What did that previous slide even mean?

  • Do cool stuff with Google Products.
  • Written in JavaScript.
  • Avoids security login hassles.
  • Enhance things by making them more useful.
  • Pretty easy to use and test. (Logger.log and debug)

So what can a Google Apps Script do?

  • Add custom menus, dialogs, and sidebars to Google Docs, Sheets, and Forms
  • Write custom functions for Google Sheets
  • Apps Script includes special APIs to let you programmatically create, read, and edit Google Apps files.
  • Build an add-on for Google Sheets, Docs, or Forms, and publish that add-on in the Google online store

Advanced Services

    You can also access some advanced Google tools:
  • Admin Directory, Admin Reports, Adsense
  • Google Analytics, Big Query, Calendar
  • Drive, Fusion Table, Gmail,
  • Google Mirror, Google +, Prediction API
  • Tasks API, URL shortener, and Youtube

Yawn

Blah, Blah, Blah. Show us something already.

  • Get JSON data from Google Sheet (GetFresh, Flashcards, LV Options)
  • Form to submit data (LV Options)
  • API calls, Get quote, update webpage (LV Options)
  • Logger, debug (LV Options)
  • Create elements on Google Drive, send emails (Timekeeper & Conference Form example)
  • Chron calls, send emails and text pages (Website Monitor Tool)

Get JSON data from Google Sheet

Discuss the use case for GetFresh.

Discuss the use case for Exercise flashcards.

Demo: Show code details using LV Options Meetup Tool.

JSON data from Google Sheet: The code is as simple as putting this in the body of your html file.

					

					
				

In the script portion of your site you would have:

					
function useJSONdata(root) {
    console.log(JSON.stringify(root, null, 4));
    // Understanding the object root is a great
    // way to understand what is going on with JSON
    var entries = root.feed.entry || [];  .. etc.
					
				

Analyse the data you need, run a for loop, create a string of content to be pasted back into the Document Object Model / HTML / body.

Comments on Scripts

The previous examples obtained data from Google sheets. Those weren't really Google Apps Script, per se, but a different way about thinking on the interface. Google Apps Script is really JavaScript code that runs on the Google servers.

    There are three types of scripts:
  • Bound to Google Apps
  • Web Apps
  • Standalone (e.g. a utility script to manage your Google Drive content)

Use Google Apps Script to call other API

  • Demo: LV options example.
  • This is a "bound to Google Apps" script.
  • Once a day go to Yahoo's API and get the current stock price.
  • Update the data within the Google Table on Google Drive.
  • Show Triggers work, including Chron and OnFormSubmit(event).

Use Google Apps Scripts to create new Drive content

  • Demo: TimeKeeper from Github example.
  • This is a "Web App" script.

All roads start at Google.com

    To run TimeKeeper:
  1. Open up your browser to google.com.
  2. Ensure you are logged in to Google. (check upper right hand corner of the page.)
  3. Click on the 3x3 box icon, then select Google Drive.
  4. Select New --> More --> Google Apps Script.
  5. Copy the contents of code.gs file from this repository to your script.
  1. In the script editor tool, choose File --> New --> HTML file. This will create a new tab in your editor.
  2. Copy the contents of index.html from this repository to your new html file.
  3. Save all files, give your project a name.
  4. "Once that basic framework is in place, all you have to do is save a version of your script, then deploy your script as a web app." See instructions at https://developers.google.com/apps-script/guides/html/

Use Google Apps Scripts to create new Drive content, email

  • Demo: Conference Form.
  • This is a "Bound to Google Apps" script.
  • From spreadsheet, create form, create calendar entry, send out email.

Just one more exciting example

Use Google Apps Scipts to send emails, SMS

  • Demo: Website Uptime Monitor.
  • This is a "Bound to Google Apps" script.
  • Check website every five minutes. Send email and SMS if site is down.

Lessons Learned, Tidbits of JS

  • How exactly does JSONP work.
  • There are some pretty interesting Google tools available.
  • There is a lot of crap on Github.

References used:

Questions, Comments?

Reveal.JS presenter tool & documentation