WEBVTT

0
00:00.060 --> 00:05.060
The first thing we're going to explore is how to authenticate ourselves with an

1
00:05.340 --> 00:10.340
API provider so that we can access more secure and more valuable data from the

2
00:11.310 --> 00:16.170
API providers. Up to this point, we've learned about API endpoints,

3
00:16.230 --> 00:20.720
so figuring out what is the URL that we need to hit up in order to get a

4
00:20.720 --> 00:24.830
particular piece of data. We also looked at API parameters,

5
00:25.100 --> 00:29.600
so passing in different inputs so that we can get different pieces of data

6
00:29.810 --> 00:31.460
back from the API provider.

7
00:32.120 --> 00:36.530
Now we're going to take one step further and look at how we can use APIs

8
00:36.530 --> 00:39.830
that require authentication. Previously

9
00:39.830 --> 00:43.580
all of the APIs that we've used were free APIs.

10
00:43.850 --> 00:48.850
They were provided completely free and we can access all parts of it without any

11
00:49.040 --> 00:51.110
sort of payment here. Now,

12
00:51.140 --> 00:56.140
this is because the data that's contained in those APIs are very simple and

13
00:56.750 --> 01:01.750
nobody is going to be using that data to build a very fancy or big commercial

14
01:02.660 --> 01:05.630
application. Now, on the other hand, there's 

15
01:05.640 --> 01:10.010
other types of data that are very valuable, for example, weather data,

16
01:10.310 --> 01:10.880
because it

17
01:10.880 --> 01:15.680
makes a lot of energy and time for somebody or some company to collect all of

18
01:15.680 --> 01:19.580
this data and provide it for you. In these cases,

19
01:19.610 --> 01:22.610
some of these APIs can have a paid tier.

20
01:23.000 --> 01:27.110
So you actually have to pay if you're running an application

21
01:27.110 --> 01:32.090
or if you have a company that needs to get this data very frequently and you

22
01:32.090 --> 01:33.980
need to get large amounts of the data.

23
01:34.820 --> 01:39.590
Why do people charge for API anyways? Well, if you think about something simple

24
01:39.590 --> 01:43.850
like the weather, it's not actually that simple. How do you even get 

25
01:43.880 --> 01:44.270
the weather

26
01:44.270 --> 01:49.270
if I asked you to figure out the weather without using some sort of website or tool?

27
01:50.660 --> 01:53.570
Well, in this particular case, open weather map,

28
01:53.780 --> 01:58.100
they have access to over 4,000 weather stations across the globe,

29
01:58.580 --> 02:03.580
and then their data scientists will take that weather data and look at the

30
02:03.680 --> 02:08.680
satellite images and process that data in order to figure out the weather and

31
02:08.720 --> 02:13.220
predict the weather for each city in the world. As you can imagine,

32
02:13.220 --> 02:16.610
that's going to be really resource-intensive and it's going to require a lot of

33
02:16.610 --> 02:21.440
employees and also server maintenance and electricity costs, right?

34
02:21.890 --> 02:26.000
So for all of that hassle, if they're going to provide this data for you,

35
02:26.270 --> 02:29.900
then it's reasonable that you should be paying for it, right?

36
02:30.380 --> 02:31.830
Essentially you can see a lot of

37
02:31.940 --> 02:35.660
APIs as a way of selling data.

38
02:36.140 --> 02:40.820
If you own some sort of privileged piece of data that you are constantly

39
02:40.820 --> 02:44.720
updating, or you are actively generating, for example,

40
02:44.720 --> 02:48.320
weather data from satellite images or financial data,

41
02:48.650 --> 02:52.940
then it's reasonable that you should be charging for this data

42
02:53.180 --> 02:57.260
especially if somebody is going to rely on it heavily in order to build a

43
02:57.290 --> 03:01.030
commercial app or a company. But luckily,

44
03:01.240 --> 03:06.240
most of these APIs provide a free tier that allows you to test out the

45
03:07.500 --> 03:08.333
application.

46
03:08.610 --> 03:12.150
And if you are somebody who's just learning the ropes then it doesn't make sense

47
03:12.150 --> 03:12.983
to charge you.

48
03:13.290 --> 03:18.090
It only makes sense when your application or your service has a lot of users.

49
03:18.480 --> 03:22.860
And then you start going into the paid tiers. Now,

50
03:22.890 --> 03:27.180
how do you prevent people from abusing this free tier?

51
03:27.210 --> 03:29.880
Because anybody can say, well, I'm just learning, you know.

52
03:30.360 --> 03:34.260
You can be somebody who's running a 1000 employee company

53
03:34.260 --> 03:36.900
and you could claim that you're just learning.

54
03:37.800 --> 03:42.240
So the way that they prevent people from abusing their service is through

55
03:42.240 --> 03:44.640
something known as an API key.

56
03:45.180 --> 03:50.160
And this is almost like your personal account number and password.

57
03:50.730 --> 03:55.730
This is the way how the API provider can track how much you're using their API

58
03:57.210 --> 04:01.110
and to authorize your access and deny you access

59
04:01.110 --> 04:03.720
once you've gone over the limit. Now,

60
04:03.780 --> 04:08.160
different API providers tend to have different ways that you can authenticate

61
04:08.160 --> 04:09.210
yourself with them,

62
04:09.630 --> 04:13.350
but most of them involve some sort of an API key.

63
04:14.100 --> 04:18.150
In the next lesson, I want to show you how we can implement the open weather

64
04:18.150 --> 04:19.140
map API,

65
04:19.500 --> 04:24.500
authenticate ourselves with an API key that we generate, and get the live wather

66
04:24.550 --> 04:28.500
data. So for all of that and more, I'll see you on the next lesson,