Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
When interacting with an API you have to register your app with the API provider. They require you to register your app so they can know who’s using their data and ensure you’re accessing it in a secure way.
Treehouse Course Recommendation
Resources:
Register and receive your Etsy API Key: Etsy Developer Tools
Publish Apps to the Web: Google Developer Account
Key Terms
API Key: a string of random characters that is unique to your app. The key is included as part of every request made to the API.
To build our sharing app we're
gonna be using two API's.
0:00
The Etsy API will allow us to get a list
of trendy items you find on the Esty site.
0:04
The Google plus API is part
of Google Play services and
0:10
will allow us to plus one and share
items we find on Etsy with our friends.
0:13
When interacting with an API, you have to
register your app with the API provider.
0:19
In this case, Etsy and Google.
0:23
They require you to register your app so
they can know who's using their data, and
0:27
ensure you're accessing
it in a secure way.
0:31
Let's get started with registration.
0:34
To register our app with Etsy,
we need to obtain an API key.
0:38
An API key is a string of random
characters that is unique to our app.
0:42
The keys included as part of
every request made to the API.
0:47
Since we include the key, Etsy knows
it's our app asking for the data.
0:51
We can register and get an API key
by going to the Etsy developer site.
0:55
Let's head there now.
0:59
We're gonna open up Chrome and
navigate to etsy.com/developers.
1:00
If you don't have an Etsy account,
you're gonna need to create one.
1:07
We can just click on
Register as a Developer.
1:09
I have an account, so
I'm gonna go ahead and sign in to it.
1:12
If you need to register,
there's a tab here to register.
1:15
Once we're signed in we're gonna
be prompted to create a new app.
1:21
So, we're gonna fill out these fields.
1:25
Application name, we're gonna use the same
name we've been using, Recommendations.
1:27
Fill out a brief description
of our application.
1:33
[SOUND] And
1:35
put in a website.
1:38
And we're building a mobile application,
so let's check that box.
1:44
For now, we're just using
ourselves to build the app, and
1:47
we're not charging for
it, so we click no here.
1:50
We're not doing any of these so
we can just leave those unchecked.
1:53
Finally just fill out the captcha.
1:59
You're gonna wanna go ahead and read
through the terms of use of the API, and
2:02
make sure that you agree with
everything for your application.
2:05
And check the box when you're done,
and click Create App.
2:08
Okay.
So we've created an app on the Etsy API,
2:14
and it gives us this
key string right here.
2:16
This is the API key we
want to use in our app.
2:19
So let's go ahead and copy it.
2:22
And now we're going to go
into Android Studio and
2:25
ace this as field in our application code.
2:28
I'm gonna to go ahead and
copy this API key into a class.
2:32
First I'm gonna go ahead and
2:36
create a new package and
this just helps to keep my code organized.
2:37
I'm gonna call this package API.
2:41
And I'm gonna create a new
class within it, called Etsy.
2:44
And the only thing right now I'm gonna
store in here is just that API key that we
2:50
got from the Etsy developer site.
2:54
[SOUND] And I'll just store it
in a variable called API key.
2:56
Okay.
3:05
The way we register our app with
Google works a little bit different.
3:05
But we start out the same way by
navigating to the Google developer console
3:09
site.
3:13
You hopefully already have a Google
Developer account from publishing an app
3:14
from a previous course at Treehouse.
3:18
But if not, you should go ahead and
create a Google account now.
3:19
There are links in the teachers notes
in case you need any help signing up.
3:23
I'm gonna go back to Chrome and
3:26
we're gonna navigate to
console.developers.google.com.
3:27
I have that pulled up here.
3:33
And once you sign in, you're gonna
be presented with this screen.
3:34
And we're just gonna wanna
click Create Project.
3:37
We're gonna give it a name.
3:40
And the project ID is auto-generated for
us.
3:42
So we just keep that as is.
3:47
Click Create and it's going to take
a moment for this to create, so
3:49
we just wait for it.
3:53
Okay.
Now that it's created,
3:56
we can go ahead and dismiss this window.
3:57
And what we want to do is go to APIs and
Auht and we want to go to APIs.
4:00
And this is a list of all the available
APIs that Google has for us.
4:06
And the one that we care about is
Google+ API, so let's go to that.
4:10
And we're just gonna go ahead and
click Enable API.
4:16
Great.
It's now enabled.
4:20
The next step we need to
do is go to Credentials.
4:22
[SOUND] Now, this is where things are a
little bit different than the Etsy API.
4:26
To begin with,
4:30
you should know that every app is signed
with a special key before it's released.
4:31
This ensures only the developer
of the app can provide
4:35
updates to the app in the future.
4:38
The key is stored in
a file called a Keystore.
4:40
During development,
4:43
Android studio uses a default
keystore called the Debug Keystore.
4:44
Tey uses this when deploying the app to an
emulator or a plugged in developer device.
4:48
When publishing an app
[SOUND] to the Play Store,
4:53
you should create a unique keystore and
key that only you have access to.
4:55
[SOUND] To use Google's API, instead of
including an API key with every call,
4:58
Google Play Services checks the key
signature of the app making the API call.
5:03
With the key signature we
registered on their website,
5:08
if they match then the API
call will be allowed.
5:11
You wanna make sure you update
the sign in key when you create
5:14
your unique key store for publishing
your app to the Google Play Store.
5:17
For full instructions and help,
I included a link in teacher's notes, but
5:21
we're gonna go ahead and
go through this process.
5:24
We're just gonna click
Create New Client ID.
5:27
And we're gonna select installed
application, and you'll see
5:30
there's a little dialogue that says we
first need to create a product name.
5:33
So let's go ahead and
click configure consent screen to do that.
5:38
Okay.
We're just going to choose the email that
5:42
we're signing with, and go ahead and
give this a product name.
5:43
We're gonna use the same
one we've been using,
5:46
and the rest of these fields are all
optional, so just go ahead and click Save.
5:49
Now we're gonna choose
Installed Application.
5:54
And we're gonna choose Android.
5:57
And there is a few different
fields we need to fill out.
6:00
The first is our package name, and
6:03
we can get that by going to our Android
manifest, and our Android Studio Projects.
6:05
So let's go there.
6:10
And in the android manifest
we have our package here.
6:11
Let's go ahead and copy that.
6:15
And then we'll paste it into the form.
6:19
And the last part of this is our
Signing Certificate Fingerprint.
6:22
And this is a hash.
6:26
And to get this we can actually go ahead
click the learn more Next to android here.
6:28
This will tell us how we obtain this hash.
6:33
So to do this, it gives us
the exact directions we need to do.
6:36
We're gonna go ahead and
just open up a terminal window.
6:39
And you can see here that it
gives us the full command.
6:44
The one thing we need to do is put
in the path to the debug keystore.
6:48
And if we're publishing this we need to
use the path to the production keystore.
6:51
For now we're just gonna
use that debug keystore and
6:56
it shows us in this note that it's
usually stored at .android/debugkeystore.
6:58
So let's go ahead and
copy this command in here, it's key tool.
7:04
Export cert alias.
7:07
Android, debug, keystore.
7:10
And then the path and it shows this in
this note right here that it's stored at
7:15
.android/debug.keystore, let's
go ahead and put that in.
7:20
And the final two parameters are list and
V.
7:28
And it's gonna ask us for
the password, and
7:32
it says right here that
the password is android.
7:34
So we just type that in, it's not gonna
show anything, but we go ahead and
7:37
type it in and hit enter, and
it give us our fingerprint.
7:40
And we need this one right here, SAA1.
7:44
So we're just gonna go ahead and
highlight it, and copy it.
7:46
And then back in the form,
7:54
we're gonna put that in under
Signing Certificate Fingerprint.
7:55
And click Create Client ID.
8:01
Great.
8:02
And that's all we need to do.
8:04
Now when we make API calls, Google Play
Services will know our package name and
8:05
the fingerprint of our application and
we'll be able to authenticate our app.
8:11
That's all we need to do on the web to
register our app and access the APIs.
8:16
Let's take a short break and then we'll
finish this setup for using Etsy's API and
8:21
Google Play services.
8:26
You need to sign up for Treehouse in order to download course files.
Sign up