1/76

2/76

Putting Together the Pieces

Building Apps with Google Apps Script

Saurabh Gupta

Product Manager, Google

3/76

?

?

?

?

DriveEye

Shared Folder Notifications

Built using Apps Script

http://goo.gl/90W4e

4/76

DriveEye - Add Folders

5/76

DriveEye - Add files to subscribed folders

6/76

2011

More Services

GUI Builder

2009

2010

2012

?

Apps Script over the years

Scripts in Spreadsheets

(Custom Functions)

UiApp & Web App

Gallery

Sharing

Scripts in Sites

7/76

8/76

Introducing

script.google.com

9/76

Create

?

?

?

Create scripts in

Google Drive

OR

script.google.com

New!

10/76

Did anything change?

All the features of Apps Script are still available

No changes to Services

No changes to Events and Triggers

More

11/76

2009

2011

More Services

GUI Builder

2012

?

Scripts in Spreadsheets

(Custom Functions)

2010

UiApp & Web App

Gallery

Sharing

Script in Sites

Container-bound scripts

Containers

Apps Script over the years

12/76

New Features of Google Apps Script

Create Standalone Scripts

1

Create

13/76

Container-bound vs. Standalone Scripts

Standalone

Container-bound

Create

14/76

Standalone vs. Container-bound - Create scripts from script.google.com

Create

15/76

Standalone vs. Container-bound Scripts

Standalone

Container-bound

Follow lifecycle of the container

Script gets deleted when parent spreadsheet is trashed

Independent lifecycle

Scripts get created, renamed, trashed from Drive

Create

16/76

Standalone vs. Container-bound - Finding Scripts

Standalone

Container-bound

Locate the parent spreadsheet and then go to Script editor.

Create

17/76

Standalone vs. Container-bound - Search using Code Snippets

Standalone

Create

18/76

Designing DriveEye - 3 Standalone Projects

Create

DriveEye

Main Project

Folder Subscription API

Data Model

19/76

What's the best way to build UI and store data?

20/76

2009

2012

?

Scripts in Spreadsheets

(Custom Functions)

2010

UiApp

Gallery

Sharing

2011

More Services

GUI Builder

Script in Sites

Apps Script over the years

21/76

22/76

New Features of Google Apps Script

Create Standalone Scripts

ScriptDb

HtmlService

Create

2

3

1

23/76

To Learn more about ScriptDb

"Storing Data using Google Apps Script"

When: June 28th, 2012

Time: 17:15pm

Where: Room 7

Who: Drew Csillag

Create

24/76

To Learn more about HtmlService and using client side JS in Apps Script

"Use what you know: Html and JavaScript in Apps Script"

When: June 28th, 2012

Time: 2:45pm

Where: Room 11

Who: Corey Goldfeder

Create

25/76

Designing DriveEye - 3 Standalone Projects

Create

DriveEye

Main Project

Folder Subscription API

Data Model

1

2

3

26/76

DriveEye - Create three standalone script projects

Create

27/76

function User(userId, driveFolders, triggerId) {this.userId = userId;� this.driveFolders = driveFolders;� this.triggerId = triggerId;�}�function DriveFolder(folderId, folderName, files) {this.folderId = folderId;� this.folderName = folderName;� // string array of files idthis.files = files;�}

Project 1 - Data model to manage folder subscriptions

Create

APPS SCRIPT

28/76

function addFolderSubscription(folderName)�function getSubscribedFolders()�function removeFolderSubscription(folderName)�function removeUser()�function getUser()

Project 2 - API to manage folder subscriptions

APPS SCRIPT

Create

29/76

How to glue standalone projects?

30/76

Share scripts to collaborate and organize your code

Create

Share

31/76

2012

?

2009

Scripts in Spreadsheets

(Custom Functions)

2010

UiApp & Web App

Gallery

Sharing

2011

More Services

GUI Builder

Script in Sites

Apps Script over the years

32/76

33/76

New Features of Google Apps Script

Share scripts in a simple way

Create Standalone Scripts

ScriptDb

HtmlService

Create

Share

2

3

1

4

34/76

Simple Sharing

Google Docs way to share scripts

Container-bound scripts inherit permissions from the parent

Create

Share

1

2

New!

35/76

Understanding Permissions

Two types of permissions View, Edit

All Viewers get Execute permissions

Share Scripts using "Share" button

Create

Share

36/76

“How does sharing help me organize my code?”

- Logical User

37/76

good ol'

Libraries

Create

Share

38/76

3 steps to create script libraries

Share script with view permissions

Save a Version of your script

Share project key

Create

Share

1

2

3

39/76

  • Convert two projects into library
    • Data model library
    • Folder subscription library

  • Include the two libraries into the main UI script

DriveEye

Create

Share

40/76

DriveEye - Create Two Libraries

Create

Share

41/76

Insert Library Project Key

4 steps for using a script library

1

2

3

4

Create

Share

42/76

Select a version

4 steps for using a script library

Create

Share

1

2

3

4

43/76

Select an identifier

4 steps for using a script library

Identifier becomes the top level class name for that library

Create

Share

1

2

3

4

44/76

Use Library with identifier

4 steps for using a script library

Autocomplete shows all the functions that are available in the library

Create

Share

1

2

3

4

45/76

function getNewFolderFromId_(folderId) {var folder = DocsList.getFolderById(folderId);� var folderName = folder.getName();� // ...var driveFolder = � new DataModel.DriveFolder(folderId, folderName, fileIds);return driveFolder;�}

Using data model library

APPS SCRIPT

Create

Share

46/76

function getFolders() {� return FolderAlertLib.getSubscribedFolders();�}��function createFolder(folderName) {� return FolderAlertLib.addFolderSubscription(folderName); �}��function removeFolder(folderName) {� return FolderAlertLib.removeFolderSubscription(folderName);�}

Using folder subscription api

APPS SCRIPT

Create

Share

47/76

What can I do with scripts?

48/76

Create

Share

Deploy

Deploy scripts as web apps

49/76

2012

?

2009

Scripts in Spreadsheets

(Custom Functions)

2010

UiApp & Web App

Gallery

Sharing

2011

More Services

GUI Builder

Script in Sites

Apps Script over the years

50/76

Understanding Web Apps

Create

Share

Deploy

APPS SCRIPT

Web App

Writes

Access

Uses

Active User

(User on the keyboard)

Bob

Bob's Data

Effective User

Sam

51/76

52/76

New Features of Google Apps Script

Deploy new type of web apps

Share scripts in a simple way

Create Standalone Scripts

ScriptDb

HtmlService

Create

Share

Deploy

2

3

1

4

5

53/76

Scripts run as the end user

Create

Share

Deploy

APPS SCRIPT

Web App

Writes

Access

Uses

Active User == Effective User

Sam's Data

Sam

54/76

Advantages of scripts running as active user

  • Scripts asks user to grant access to resources
  • Scripts identifies the end-user
  • Script uses end-user's quota
    • Scripts have execution quota. Quota is tied to the account which executes the script.

Create

Share

Deploy

55/76

Two types of Web Apps

Create

Share

Deploy

APPS SCRIPT

Web App

Active User and Effective User is the same end-user

Active User is the end user

Effective User is the developer

New!

56/76

How to Deploy a web app

Create

Share

Deploy

Select versions

Select type of web app

Access Control

57/76

Versioning for Web Apps

  • Immutable Url for web apps
  • Change versions without affecting users
  • Development Url for testing

Create

Share

Deploy

58/76

function doGet(e) {var html = HtmlService.createFromFile(...);� // ... more code// ... more ui codereturn htmlOutput;�}

DriveEye - Writing a simple web app

Create

Share

Deploy

APPS SCRIPT

59/76

function addFolderSubscription(folderName) {// ...// create a new triggervar triggerId =

ScriptApp.newTrigger("hasNewFiles")� .timeBased().everyMinutes(5)

.create().getUniqueId();� // ... �}

DriveEye - Creating Triggers for each user

APPS SCRIPT

Create

Share

Deploy

60/76

How do users find your web app?

61/76

Create

Share

Deploy

Publish

62/76

2012

?

2009

Scripts in Spreadsheets

(Custom Functions)

2010

UiApp & Web App

Gallery

Sharing

2011

More Services

GUI Builder

Script in Sites

Apps Script over the years

63/76

64/76

New Features of Google Apps Script

Integration with Chrome Web Store

Deploy new type of web apps

Share scripts in a simple way

Create Standalone Scripts

ScriptDb

HtmlService

2

3

1

4

5

6

Create

Share

Deploy

Publish

65/76

Create

Share

Deploy

Publish

New!

66/76

  • Easy steps to verify ownership
  • One click uploads in Chrome Web Store

What's so special about Chrome Web Store integration?

Create

Share

Deploy

Publish

67/76

Verify the ownership using Google Webmaster Central

    • Copy the meta-tags from Webmaster Central
    • Paste the meta-tags in "Register with Chrome Web Store dialog"

Create

Share

Deploy

Publish

1

2

3

4

68/76

Register the Web App in Chrome Web Store

    • Required to register as a developer on Chrome Web Store
    • From Script editor, click Publish > Register with Chrome Web Store
    • Every application in Chrome Web Store needs a manifest
    • Visit Developer Dashboard in Chrome Web Store to view the uploaded item

Create

Share

Deploy

Publish

1

2

4

3

69/76

Customize Listing Chrome Web Store

    • Standard Chrome Web Store requirements
    • Icons, Screenshots and Display Images
    • Good quality assets == Better rank in Chrome Web Store

Create

Share

Deploy

Publish

1

2

3

4

70/76

Publish and go live !

Create

Share

Deploy

Publish

1

2

3

4

71/76

Create

Share

Deploy

Publish

Completing the story

DriveEye

Shared Folder Notifications

72/76

Demo of DriveEye

73/76

New Features of Google Apps Script

Integration with Chrome Web Store

Deploy new type of web apps

Share scripts in a simple way

Create Standalone Scripts

ScriptDb

HtmlService

2

3

1

4

5

6

Create

Share

Deploy

Publish

74/76

script.google.com

#io12

75/76

script.google.com

#io12

76/76