WESLEY CHUN: Hey everyone, this is Wesley Chun,
an engineer and developer advocate here at Google.
If you've been wanting to integrate Google technologies
into the apps that you create, this
is the right place to get started.
In this episode, we'll cover the setup process
when you want to build an app that uses Google APIs.
First of all, why Google Developer Tools at all?
Well, in the last episode-- click
the link if you missed it-- we mentioned
that people are familiar with tools like Google Search
and YouTube.
But can you imagine having to create your own Google
Maps or Google Drive?
Well, we can't either.
There's no need to reinvent these wheels when
you can use our APIs and open source developer tools to tap
into these technologies.
Today, we'll show you how easy it is to get started.
You'll learn how to create a project in the Developer
Console-- or DevConsole-- and how
to enable the APIs you wish to use.
Finally, you'll learn how to get the credentials your app needs
to access Google APIs, whether you're
accessing authorized data or using simple API keys
to access public data.
In upcoming episodes, we'll create
scripts using these credentials to access Google APIs.
This common code will be the same regardless of app,
how may APIs it uses, or what language.
By the way, if you're not accessing authorized data,
the required code is even shorter.
Your code will be able to access Google services from anywhere,
whether it's a client-side web app, a mobile app,
or a back-end service running in the cloud.
Because the approach to all are very similar.
All you need to do to get set up is done in the browser.
So let's go to the computer now.
All right, here we go.
Any time you're running an app using Google APIs or the Google
Cloud Platform, you need to go to the Developer's Console,
or DevConsole.
So pop open a browser to console.developers.google.com
and log in with your credentials if you haven't already.
If you don't have a Google account yet,
then click on the Create Account link
that you see just below to get started.
Once you're logged in, you'll be brought
to the DevConsole's home page, which
is an overview of all of your projects.
Don't worry if you haven't created one yet.
It'll just be blank instead of having a list of them.
Here, we're going to be doing three things.
One is to create a new project.
Two is to turn on the APIs you're
going to use for that project.
And three, you're going to create and download
the appropriate credentials.
To begin, let's create a project by clicking on the blue Create
Project button.
You need to provide two things.
One is the project name, which is
used only here in the DevConsole--
so you can change it later if you don't like it.
The second thing you need to provide is a project ID.
This uniquely identifies your project
over all the others in the system.
And because of that, you can't change it later, so make it
a good one.
For your convenience, Google creates a random one for you,
like the one you see here.
If you don't like it, pick your own, if it hasn't already
been chosen, or click on the little refresh wheel over here,
and Google will make another random one for you.
Once you've decided, click on Create.
A bunch of gears will start spinning around inside Google
data centers to create your project.
It usually takes about half a minute
to get the project set up.
Once it's ready, you'll be taken to your new project's
dashboard, which is where we'll pick up.
So go ahead and pause the video to do
that, then resume once you've landed on your new project's
homepage.
Great, our project was created successfully.
So here we are on our project's Overview page.
To keep things simple, our project
will just be a command line script.
It could be also a mobile client or a server-side app running
in the cloud.
We'll show you where those other options come in later.
For now, the next step is to enable APIs.
And yes, there is an app for that,
which is this Enable an API button.
You'll be taken to the services page, where
you can turn on APIs you wish to use.
You'll see that some Google Cloud Platform services have
already been enabled by default.
So if you're not interested in using them,
feel free to toggle them off using the switches
that you see here on the right-hand side.
Now it's time to find the APIs that you want to enable.
For example, if you're interested in using the Google
Drive API, just scroll down and flip it on.
There it is.
Next, let's say you wanted the YouTube data API.
Well, you'd scroll down to find that and turn it
on in the same way that you would turn on any other API.
Once you're done selecting the APIs that you wish to use,
scroll back up to the top to ensure that they've
been turned on, like we see here.
Now let's set up our credentials by selecting that link
on the left.
On this page, we see two sections-- authorized
and public API access.
We're going to create credentials for both.
For Google Drive, you should recognize
that files and folders are user data,
meaning that your app needs to be authorized in order to get
access to that type of data.
So let's do that by clicking on the Create New Client ID
button.
Here, we see a dialogue to enter our application type.
Since it's a simple command line script,
it's neither a web app nor an app running on a Google server
acting on behalf of a user, which
is what a service account is for.
Instead, we're creating an installed app, so select that.
Now, it's neither a web nor a mobile installed app,
but a command line script instead.
So that means Other.
Now click Create Client ID to generate your OAuth
credentials.
The last step in this section is to click on the Download JSON
button.
This will save the credentials file that your script will
use in order to communicate with Google
Service for authorization.
Naturally, we'll recommend you drop that file
into the same folder as to where you're going to build your app,
like we did here.
So now that's done.
Going back and taking a look here
at the second half of the Credentials page,
we see this is for simple or public API access, meaning
you'll be creating an API key.
It's primarily used for APIs where you're just
accessing the service, like searching for YouTube videos.
In such cases, just having an API key
is good enough, as there's no need for authorization here.
Click on the Create New Key button.
Again, we have just a command line script,
which is neither a web nor a browser app.
So it's technically a server app, so select that.
You can also choose to whitelist IP addresses if you wish.
Otherwise, click Create.
In a few seconds, you'll have an API key-- ta-da!
This is a string that you can copy and paste directly
into your code, which is fine for experimenting with.
But obviously, this isn't secure in practice.
So if you're doing this for production,
make sure you put it into a secure database
or someplace other than plain text and code, all right?
Anyway, now you've got authorized and public API
access.
So our mission in the DevConsole is complete.
The rest is up you.
All right, now that you've got a project set up,
you're ready to start coding.
In the next episode, we'll walk you through the common security
code necessary to use Google APIs.
Well, that's it for now.
Be sure to bring your code editors next time.
This is Wesley Chun from Google, and we'll
see you again soon on the Launchpad.