[MUSIC PLAYING]
WESLEY CHUN: Welcome to part three
of our series on using G Suite APIs for student developers.
This is developer advocate, Wesley Chun.
Previously, we discussed how to use G Suite REST APIs.
Now, we'll switch gears to show you a higher level
way of accessing those APIs.
We'll switch from Python to JavaScript
and drop all the security code, as it's automatically generated
for you by Google Apps Script.
So what is Apps Script?
Well, I think of it as another Google secret.
But it's actually not a secret, nor is it
well kept, since it's been out for over a decade.
It is JavaScript.
But instead of using REST and HTTP with OAuth,
you use built-in objects to talk to Google APIs.
Also, you don't have to write the OAuth code,
because it's automatically generated for you.
Now while it is server-side like node,
it's more like using JavaScript as a programming language,
rather than for a synchronous event-driven web apps.
Now a one liner describing Apps Script looks like this.
It's serverless, meaning no VMs, because we host and run
your code.
It helps automate repeated tasks,
extends the functionality of G Suite editors,
connects to non-Google Cloud products,
like maps, analytics and YouTube.
And lets you access external databases
or other online services.
Now let's get started with a Google Sheet.
It's got many functions, but are there any magic ones
that only Sheets has?
Well, how about Google Finance?
It's a great way to pull up the latest stock
price on your favorite company.
Cool, right?
Well, we'll come back to functions later.
But for now, let's code Sheets without using a REST API.
Is that possible?
Yep, can do.
Just pull down the Script editor under Tools.
And here's your Hello World.
A one-line JavaScript application
that writes Hello World into the upper left cell of a sheet.
You know, A1, look, Ma, no OAuth code.
Yet the prompt still appears when you save and run it.
Now, the output is as expected.
Check the video for a longer Apps Script intro.
Now back to magic functions.
Here's another one, Google Translate.
Now those are cool, but they're Google products, right, Finance
and Translate.
Well, what if I wanted to write a function that
checked today's Bitcoin prices?
Well, that function doesn't exist.
But using Apps Script, you can create custom functions.
Here, I'm calling one of the many Bitcoin APIs
out there to get today's price.
Check out the sample code if you get a chance.
And whoo whoo, I've just created my own custom function.
Now, what can we do with this?
Well, instead of Hello World, we've got a real piece of data
now.
Happens to be the address for the Google New York office.
There's also a header row, so bear in mind,
we need to read cell A2.
Now here's a four-line app that does something kind of useful.
Like before, we access the Sheets active sheet,
but instead of writing to a cell,
we read the address from it.
But we can also pass that address to Google Maps
and ask it to create a map with a pin or a marker
on that address.
Finally, we can call the Gmail API
to send this map to my friend, to tell
him to come to the Google New York office
to meet me for lunch.
Check out the video for more details.
Now, where can you go from here?
Maybe your sales team needs to visit several customers
in New York.
Or perhaps you manage a book club.
Well, create a custom map for members
coming to the next meetup.
Now don't forget, Maps also has walking and public transit
directions, all accessible from Apps Script as well.
Now, we've shown how you can create
custom functions and Sheets bound scripts
using Apps Script.
What else can it do?
Well, if you've ever heard of add-ons before,
they're also powered by Apps Script.
Add-ons let you extend the functionality of Google Docs,
Sheets, Slides, Forms and Gmail.
It also powers App Maker, Ad Scripts and Google Data Studio
community connectors.
Now, let's look at add-ons, starting with Slides.
Ever want to make a progress bar for your decks to let you
and the audience know how much is left?
Well, slide bars are not exactly native to presentation
software, but we can build an add-on
that extends the functionality of Google Slides.
Here's the progress bar code.
It calculates how many slides you have in total,
then creates relatively sized rectangles on each slide.
Check out our blog posts and video for a deeper dive
into this sample.
Next, let's say you're a busy working professional going
on a business trip.
You want to get reimbursed for your airfare and hotel, right?
Well, for that, you need to create
what is called an expense report for your manager.
But since you get all of your receipts
in Gmail, why can't you do the expense report there?
Well, you can with the Gmail add-on.
Here, you can see that we're kind of in Gmail,
but let's give you the whole picture.
Gmail add-ons show up in the right nav.
Ours does expenses, so we picked an icon
that looks like a receipt, or sort of looks like a receipt.
One awesome bonus with Gmail add-ons,
is that they run on web and mobile.
Meaning you don't have to write two versions of your app,
and they work seamlessly on both.
The only difference is that the add-on icons show up
on the bottom on mobile.
Now, the add-on extracts the relevant data from the receipt,
like the date, the amount, the vendor,
then pre-fills in and pops up this form.
All you do is supply a link to Google Sheet.
And once all of your expenses are logged successfully,
you'll have a sheet with all of your expenses,
which you can export as a PDF and send
to your manager for approval.
Cool, right?
Well, check out the blog post and video for more info
and code snippets.
Now that you know how to use Apps Script and G Suite REST
APIs, join my colleagues for the next set
of videos demoing medium-sized apps that
do cool things with these G Suite developer tools.
This is Wesley Chun from Google, and thanks for watching.
[MUSIC PLAYING]