In this section, we will get more familiar with the YouTube API.
In the appendix of this section, you will find the link to the YouTube API documentation that you see
on the screen.
We will use these docs to help us build the URL needed to interact with the API in our Python scripts.
So let's go over an example by looking at the resources on the left hand side, and we can start off
with the videos resource.
As you can see by clicking on it, this resource supports many methods like list, insert, update and
more.
In our case, we will always use the list method for all resources.
If we were to click on the overview section.
And scroll down you will find the resource representation which is this one over here.
Here you will see a JSON structure which shows the key names and the value type in terms of important
keys.
If we scroll down to the statistics key.
Ski.
Which is this one?
Over here you can see that there are statistics such as view count, like count, comment count and
more.
These are important metrics for videos, so we will for sure use these variables inside our data warehouse.
If you have to click on the statistics key, it will take you to the properties table where you will
find more information on each sub property.
Now that we have seen the basic structure of a resource, we will need to understand what parameters
are needed to make the API call.
To do this, go to the list method under videos.
Scroll down to parameters and check what is required and what is optional.
Under required parameters you will find part which is of type string and we need to select at least
one of these key names.
We know that in our case we will use statistics for sure, which is this one, and we will see what
other keys we'll need as we go along.
Apart from part, we also need to specify one of the parameters under filters.
shoulders.
Here it is important to specify just one as is instructed in this comment here.
In our case, we will use the ID key, which represents the unique ID of a video to illustrate what
we just discussed.
We can use the functionality provided by YouTube themselves, which you see on the right hand side under
APIs.
Explore the API explorer.
Functionality is a way of testing API calls using the request parameters and the API key we generated
in a previous lecture.
So if we make sure we are under the API and increase the screen to full size, we can build the API
URL that we need for our Get request.
As we just saw, we will need at least one variable for part which we can set to statistics.
And for filter we need to choose between chart ID and my rating.
We will use ID and I happen to have a video ID we can use.
I will show you how I got this ID very soon.
For now, just know that the video ID is a unique ID for one of Mrbeast's YouTube channel videos and
the video ID we can write it under the id parameter as such.
Scrolling down, if you see Google OAuth 2.0 ticked, just untick it as we won't be needing the API
key.
We can now press execute and you should get a 200 response, which is a successful response, meaning
everything is okay.
If you don't get a 200 response, make sure you inputted the request parameters correctly in the response.
You can see the statistics for this particular video which is these.
Over here.
We can verify these numbers by going on YouTube and typing in the unique ID.
So let's get this from here.
We go on YouTube and we search for this video.
As you can see, the corresponding Mrbeast's YouTube video appears.
You can see it's his channel and we have to go on it.
We can verify the parameters that we just saw over here.
So the views was this number, the comments, this number and the likes.
It was this number.
Something else worth noting is that the video ID that I showed you here is also present in the URL.
Now, I will say that on the day that I created the API key, I tried the API explorer feature, but
I was getting a 403 response telling me that my quota was exceeded even though I hadn't done any tests.
As you can see here.
So for some reason this also happens to you.
I will show you another way that I ran the same test using a tool called postman.
This is not a program that you need to install from your end, but I just want to show you other ways
of testing out APIs.
So you do this by copying the URL under curl.
Going into postman.
Copying and pasting it here.
Make sure that we are selecting the get method for the key you see here.
Make sure that you use the key you created in one of the previous lectures.
For convenience sake, I have put the link where you will find the API key in the appendix of the section,
which is over here.
Just press show key and you will get the API key you created.
Copy it.
Go back to postman.
And once we click send we could get a 200 response.
And in fact we did.
This means that we have a successful request.
Notice how at the bottom you will get the same response that we saw in the API explorer with the statistics
key value pairs showing here.
That concludes this section on getting more familiar with the YouTube API, and also using the API Explorer
and Postman to get a response.
That's it for this lecture, and I'll see you in the next section where we will set up a git remote.