WESLEY CHUN: Hey, students.
Many of you know how to use Gmail, Google Drive, and Docs,
and that's great.
But did you can code them too?
Hi.
This is Wesley Chun, your friendly developer advocate
from Google Cloud.
In this series for student developers,
we aim to add G Suite as another tool in your career portfolio,
giving you the ability to code those apps you know so well.
What's G Suite again?
Well, productivity tools like a word processor, spreadsheets,
and presentation software in the form of Google Docs, Sheets,
and Slides.
Add in Gmail, Google Drive, Calendar,
and you've got the core components of G Suite.
Don't forget about Google Forms and Hangouts.
Now, paying customers get even more tools.
While many of you know how to use G Suite,
behind each app is a developer API,
meaning you can code Gmail, Google Drive, Calendar, Docs,
Sheets, and Slides.
G Suite is one part of Google Cloud along with the Google
Cloud Platform, you know, compute, storage, networking,
security, serverless and machine learning tools
that you can rent in the cloud?
Well, in addition to Cloud, Google
has other apps for users, like Search, Chrome, YouTube,
and Android.
But you can't wait for Google to build every possible app,
and we don't work in all industries.
Instead, wouldn't it be better if we gave you
the tools to build amazing new apps
to enable your own success?
So you don't have to reinvent the wheel on the road
to success, we've made a lot of our tech available to you
in the form of APIs.
Use them to build your next web app, mobile app,
or more likely both.
But some have told us that using Google APIs is challenging.
So let's break down those barriers
to help everyone use Google APIs.
The hub of Google API activity is the Google Cloud Platform
console that you access at console.cloud.google.com.
It's where you manage your apps, called "projects."
Most of its features are for Google Cloud Platform,
like choosing which GCP tools to use, managing GCP billing,
managing other project developers,
and selecting the APIs you'll use.
Only GCP users need to use the first pair,
so check out the Cloud video console to learn more.
Now, you don't have to worry about billing in the console
because G Suite and GCP APIs are built differently.
GCP services are pay per use.
That's what the billing component in the console
is for.
But G Suite API usage is at no additional charge
on top of its subscription fee, whether it's
the pay-for Business Edition or the free Gmail Consumer
version.
Let's take a closer look at the API Manager.
Now, this developer's console has three tabs.
The Dashboard is to see stats on your app,
like how much traffic you're getting, the number of errors
it's generating, and how fast it responds to users.
The second tab is to enable or disable which APIs to use.
Now, none of the G Suite APIs are on by default.
So pick and choose the ones to toggle on or off.
The last tab is to create credentials like API keys
and OAuth clients.
Check out the video to get more details
on using the dev console.
You can access the API Manager directly
at console.developers.google.com.
To access Google APIs, we recommend
using our client libraries.
We'll demo in Python and JavaScript,
but many other languages are supported,
and all of the client libraries can be downloaded from the link
that you see on screen.
Before getting started, heads up,
there are two types of APIs, simple and authorized.
Simple APIs are for accessing public data,
like searching for places on Google Maps,
querying for YouTube videos, or sending a sentence to the Cloud
Natural Language API.
However, if your code requires access
to user or application data, you need authorized access.
Make sense?
For user data, that's user authorization.
And for app data, that's service account authorization.
Both are basically the same except for who owns that data.
Regardless, to get started with a new project,
go to the API Manager and create a project
or reuse an existing one.
Then enable the G Suite or GCP APIs you wish to use.
Finally, create the appropriate credentials
to talk to Google APIs.
Since most G Suite data is owned by users,
you'll create OAuth 2 client ID.
However, if your data is owned by an app
or you're using GCP services, create
service account OAuth credentials instead.
In either case, download the JSON
file with those credentials once they've
been created because your code needs
this to talk to Google servers.
User auth code looks something like this.
And by the way, service account code is similar.
We're always trying to improve the library.
So while the names may change, the structure
will stay consistent.
This example is in Python.
But regardless of what language you use, after your imports
are the permission scopes that you want your user
to grant to your app.
Next is a security code.
Now, authorized APIs require valid OAuth tokens,
and this block checks to see if you have them.
If not, it puts together your credentials plus the permission
scopes and prompts the user for it.
It's that OAuth permissions box that you see whenever you run
the app the first time, right?
Check out the video for a deeper,
line-by-line explanation of the code.
Once you get the OK from your user,
create an endpoint to talk to the API.
Now service account auth is a bit simpler
because you don't have to ask a user to grant permissions.
The owner of the data, which could be you,
will have already trusted you enough
to create service account credentials for you.
Well, whichever you're using, the auth code
generally stays the same.
Now, the only things that really change
are the bolded lines that you see, the permissions scopes
and what APIs you use.
So what does actual API usage look like?
Well, everything happens in a request-response workflow.
Your app makes a request, credentials are confirmed,
the request to service and response is returned.
It's very much of a client-server model.
Congrats.
You've finished our primer on Google and especially G Suite
APIs.
In the next few videos, we're going
to dig into actually using G Suite developer tools.
If you're still hungry for more after this series,
tune in to the G Suite Dev Show where I help you
dive even deeper.
This is Wesley Chun, and thanks for tuning in.
[MUSIC PLAYING]