WEBVTT

00:04.160 --> 00:07.320
In this section, we will get more familiar with the YouTube API.

00:07.680 --> 00:12.440
In the appendix of this section, you will find the link to the YouTube API documentation that you see

00:12.480 --> 00:13.280
on the screen.

00:14.200 --> 00:20.120
We will use these docs to help us build the URL needed to interact with the API in our Python scripts.

00:20.640 --> 00:26.400
So let's go over an example by looking at the resources on the left hand side, and we can start off

00:26.400 --> 00:27.760
with the videos resource.

00:29.800 --> 00:35.800
As you can see by clicking on it, this resource supports many methods like list, insert, update and

00:35.800 --> 00:36.200
more.

00:37.120 --> 00:41.440
In our case, we will always use the list method for all resources.

00:42.560 --> 00:44.680
If we were to click on the overview section.

00:46.760 --> 00:51.720
And scroll down you will find the resource representation which is this one over here.

00:52.880 --> 00:59.800
Here you will see a JSON structure which shows the key names and the value type in terms of important

00:59.840 --> 01:00.200
keys.

01:00.240 --> 01:02.600
If we scroll down to the statistics key.

01:02.600 --> 01:02.680
Ski.

01:05.360 --> 01:06.280
Which is this one?

01:06.280 --> 01:12.680
Over here you can see that there are statistics such as view count, like count, comment count and

01:12.680 --> 01:13.080
more.

01:13.640 --> 01:19.560
These are important metrics for videos, so we will for sure use these variables inside our data warehouse.

01:20.080 --> 01:24.480
If you have to click on the statistics key, it will take you to the properties table where you will

01:24.480 --> 01:27.120
find more information on each sub property.

01:27.560 --> 01:31.880
Now that we have seen the basic structure of a resource, we will need to understand what parameters

01:31.880 --> 01:33.920
are needed to make the API call.

01:34.280 --> 01:36.920
To do this, go to the list method under videos.

01:38.760 --> 01:44.360
Scroll down to parameters and check what is required and what is optional.

01:44.800 --> 01:50.360
Under required parameters you will find part which is of type string and we need to select at least

01:50.360 --> 01:51.600
one of these key names.

01:52.320 --> 01:58.800
We know that in our case we will use statistics for sure, which is this one, and we will see what

01:58.840 --> 02:00.480
other keys we'll need as we go along.

02:01.440 --> 02:05.120
Apart from part, we also need to specify one of the parameters under filters.

02:05.120 --> 02:05.160
shoulders.

02:05.560 --> 02:09.960
Here it is important to specify just one as is instructed in this comment here.

02:10.120 --> 02:16.440
In our case, we will use the ID key, which represents the unique ID of a video to illustrate what

02:16.440 --> 02:17.120
we just discussed.

02:17.160 --> 02:22.480
We can use the functionality provided by YouTube themselves, which you see on the right hand side under

02:22.480 --> 02:23.000
APIs.

02:23.000 --> 02:24.880
Explore the API explorer.

02:24.880 --> 02:30.480
Functionality is a way of testing API calls using the request parameters and the API key we generated

02:30.480 --> 02:31.560
in a previous lecture.

02:32.280 --> 02:38.560
So if we make sure we are under the API and increase the screen to full size, we can build the API

02:38.560 --> 02:41.120
URL that we need for our Get request.

02:42.080 --> 02:47.400
As we just saw, we will need at least one variable for part which we can set to statistics.

02:50.640 --> 02:54.240
And for filter we need to choose between chart ID and my rating.

02:54.480 --> 02:59.880
We will use ID and I happen to have a video ID we can use.

03:00.040 --> 03:02.440
I will show you how I got this ID very soon.

03:02.720 --> 03:08.520
For now, just know that the video ID is a unique ID for one of Mrbeast's YouTube channel videos and

03:08.520 --> 03:13.200
the video ID we can write it under the id parameter as such.

03:14.040 --> 03:21.440
Scrolling down, if you see Google OAuth 2.0 ticked, just untick it as we won't be needing the API

03:21.480 --> 03:21.880
key.

03:21.920 --> 03:27.920
We can now press execute and you should get a 200 response, which is a successful response, meaning

03:27.920 --> 03:28.800
everything is okay.

03:29.440 --> 03:35.600
If you don't get a 200 response, make sure you inputted the request parameters correctly in the response.

03:35.600 --> 03:39.720
You can see the statistics for this particular video which is these.

03:39.720 --> 03:40.400
Over here.

03:40.400 --> 03:45.320
We can verify these numbers by going on YouTube and typing in the unique ID.

03:46.520 --> 03:48.040
So let's get this from here.

03:49.640 --> 03:54.400
We go on YouTube and we search for this video.

03:57.680 --> 04:02.400
As you can see, the corresponding Mrbeast's YouTube video appears.

04:02.400 --> 04:05.480
You can see it's his channel and we have to go on it.

04:08.200 --> 04:12.920
We can verify the parameters that we just saw over here.

04:12.920 --> 04:17.840
So the views was this number, the comments, this number and the likes.

04:17.880 --> 04:19.000
It was this number.

04:19.200 --> 04:26.120
Something else worth noting is that the video ID that I showed you here is also present in the URL.

04:26.360 --> 04:31.720
Now, I will say that on the day that I created the API key, I tried the API explorer feature, but

04:31.720 --> 04:38.640
I was getting a 403 response telling me that my quota was exceeded even though I hadn't done any tests.

04:38.720 --> 04:39.880
As you can see here.

04:39.920 --> 04:42.000
So for some reason this also happens to you.

04:42.040 --> 04:46.680
I will show you another way that I ran the same test using a tool called postman.

04:47.720 --> 04:52.520
This is not a program that you need to install from your end, but I just want to show you other ways

04:52.520 --> 04:53.960
of testing out APIs.

04:55.440 --> 04:59.800
So you do this by copying the URL under curl.

05:01.120 --> 05:02.560
Going into postman.

05:04.840 --> 05:06.520
Copying and pasting it here.

05:07.160 --> 05:12.600
Make sure that we are selecting the get method for the key you see here.

05:13.200 --> 05:16.480
Make sure that you use the key you created in one of the previous lectures.

05:16.880 --> 05:23.240
For convenience sake, I have put the link where you will find the API key in the appendix of the section,

05:25.160 --> 05:27.080
which is over here.

05:28.040 --> 05:32.480
Just press show key and you will get the API key you created.

05:33.040 --> 05:33.760
Copy it.

05:34.760 --> 05:36.160
Go back to postman.

05:40.240 --> 05:43.920
And once we click send we could get a 200 response.

05:44.080 --> 05:45.120
And in fact we did.

05:45.160 --> 05:47.360
This means that we have a successful request.

05:47.400 --> 05:52.880
Notice how at the bottom you will get the same response that we saw in the API explorer with the statistics

05:52.920 --> 05:55.160
key value pairs showing here.

05:56.400 --> 06:02.760
That concludes this section on getting more familiar with the YouTube API, and also using the API Explorer

06:02.760 --> 06:04.440
and Postman to get a response.

06:05.600 --> 06:10.480
That's it for this lecture, and I'll see you in the next section where we will set up a git remote.
