In the last section we generated a YouTube API access key.
Now we're going to learn how we can take this key and actually initiate a search of the YouTube API.
The first thing we need to do is look at some documentation around that process.
So back inside of my browser I'm going to open up a new tab and I'll do a search for something like
YouTube API search like the one the first results on here is search Colan list at the YouTube v3 docs.
So take a look at that.
All right.
So to be honest with you personally this documentation isn't the most helpful thing in the world.
It's kind of hard to read sometimes.
Let me show you why that is.
If you scroll down a little bit on this page you'll see that it gives you a nice little code snipped
right here.
You can use to figure out exactly how to make a request so we could click on Javascript.
But when you do so you'll notice that they kind of reference this function that they put together in
their documentation somewhere else called Build API request so the documentation doesn't make it super
clear exactly how we make requests to do a search based on this little code snippet alone.
But nonetheless I'll tell you exactly what we need to be doing here.
All right.
So if you scroll down a little bit more you'll notice the section called the request right here.
So essentially what we need to do is make a get type request to this your L Google API dot com slash
YouTube the three search.
When we make a request over there we will pass in some number of query string parameters and you can
see the preceding parameters that you and I are going to pass in listed right here.
So first off is part and we're going to set that equal to snippet.
The purpose of part right here is to essentially tell the YouTube API what information that we want
to retrieve about each particular video that we end up finding the term snippet essentially says to
the API.
Send us back a snippet summary of the entire video and so that will give us information like the video's
title description a link to the video.
The author a lot of other useful stuff like that.
The next parameter right here called Max results is pretty self-explanatory.
We put in the number of results we want to get back from the search process for you and I we're going
to be using a max results of 5 just because that's going to end up looking pretty good on a UI we're
putting together without a doubt you could increment the max results to be greater than 5.
I'm just saying that for our application we're going to start off by just showing 5 videos at a time.
And then finally the other parameter we're going to pass in here is q which is short for queery.
So it's going to be the actual search term that we want to attempt to make.
All right.
That's pretty much it.
You know to be really clear these different properties you see right here are query string parameters.
And so with X-ers we passed those in on that harams object or the configuration object just as we did
previously with the splash API.
All right.
So it then mind we're going to flip back over to our editor and inside the YouTube G-S file We're going
to start to set up accedes.
We're going to create and pre-configured instance of Axel's just as we had previously we have not installed
Axel's into our project yet.
We will do so in just a moment but for now let's just write out some code inside this YouTube dachas
file of imagining that we had already installed it.
So at the top I'll say X import accedes from ASIO's and then a little bit lower.
I'll say export default accedes dot create.
So remember the idea here is that we are going to make a pre-configured instance of Axel's that already
has a base you are l and some default parameters loaded into it.
So I get to specify a base you are l.
Notice the capital U R L and then for the base you are l.
I went to put in everything up to the three like so it's like in pace that.
And I'll flip back over and I'll paste it in like so.
Now notice that this you are right here does not have a ending slash.
It's just v3 on its own.
So remember the idea behind this space Eurail is that later on we'll be able to get our instance of
this X-posts that we are creating right here and we'll be able to say something like YouTube.
Don't get slash search.
And then the string right here search we can imagine is taken in kind of like appended onto the end
of the base rail like so
now after the base you are out.
We're going to stick in a Options object here called Puranas and this is going to contain all the different
queery string parameters that we want to have added onto the request.
So remember the first one is going to be required part and we're going to set equal to snippet.
So I'll say part and I'll said it equal to the string snippet.
Except we're going to do a max results of five.
And then finally it's not specifically mentioned inside the documentation right here but we actually
have to depend on our API key to this request as well inside the query string.
So you're not going to see it on this particular page right here.
Like I think we could even do a search on here for key and we're not going to find anything about it
on here.
But essentially whenever we make our final request we have to throw our API key into a query string
on the or L and so the final results of that would look like questionmark key equals and then our X
Eski of like you know AIC or whatever it is in order to do so.
We're going to add on key and that's going to come from our key variable.
All right.
So that's pretty much it.
Now you'll notice that the one thing we are missing here is a queue of Sayne like you know a surfboards
or something like that.
That's because we are going to specify our queery only when we actually make use of this X-ists instance
and send a request over to the Google API.
So we do not want to pre-configured our query or the search term on this instance right here.
We're going to pass in that query string were that thing that we want to do our search for when we actually
make use of this instance.
All right.
That's it for our YouTube chase file.
Now the last thing on doing side of your is make sure that we install X is so to do so I'll flip back
over to my terminal.
Here's my running project all hit Control C and then I'll do an NPM install dasht are safe access like
so now this will just take a second or two to install some skin to let it go very quickly and then when
it's all done I'll make sure that I start my server back up with NPM start
right.
Very good.
OK.
So let's take a quick pause right here.
When we come back the next section we're going to try out that YouTube API from our app component and
then we'll start to wired up to our search bar and make sure that any time that someone submits a search
term we try to make an actual request to the YouTube API.