第 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 页