1 00:00:00,060 --> 00:00:05,060 The first thing we're going to explore is how to authenticate ourselves with an 2 00:00:05,340 --> 00:00:10,340 API provider so that we can access more secure and more valuable data from the 3 00:00:11,310 --> 00:00:16,170 API providers. Up to this point, we've learned about API endpoints, 4 00:00:16,230 --> 00:00:20,720 so figuring out what is the URL that we need to hit up in order to get a 5 00:00:20,720 --> 00:00:24,830 particular piece of data. We also looked at API parameters, 6 00:00:25,100 --> 00:00:29,600 so passing in different inputs so that we can get different pieces of data 7 00:00:29,810 --> 00:00:31,460 back from the API provider. 8 00:00:32,119 --> 00:00:36,530 Now we're going to take one step further and look at how we can use APIs 9 00:00:36,530 --> 00:00:39,830 that require authentication. Previously 10 00:00:39,830 --> 00:00:43,580 all of the APIs that we've used were free APIs. 11 00:00:43,850 --> 00:00:48,850 They were provided completely free and we can access all parts of it without any 12 00:00:49,040 --> 00:00:51,110 sort of payment here. Now, 13 00:00:51,140 --> 00:00:56,140 this is because the data that's contained in those APIs are very simple and 14 00:00:56,750 --> 00:01:01,750 nobody is going to be using that data to build a very fancy or big commercial 15 00:01:02,660 --> 00:01:05,630 application. Now, on the other hand, there's 16 00:01:05,640 --> 00:01:10,010 other types of data that are very valuable, for example, weather data, 17 00:01:10,310 --> 00:01:10,880 because it 18 00:01:10,880 --> 00:01:15,680 makes a lot of energy and time for somebody or some company to collect all of 19 00:01:15,680 --> 00:01:19,580 this data and provide it for you. In these cases, 20 00:01:19,610 --> 00:01:22,610 some of these APIs can have a paid tier. 21 00:01:23,000 --> 00:01:27,110 So you actually have to pay if you're running an application 22 00:01:27,110 --> 00:01:32,090 or if you have a company that needs to get this data very frequently and you 23 00:01:32,090 --> 00:01:33,980 need to get large amounts of the data. 24 00:01:34,820 --> 00:01:39,590 Why do people charge for API anyways? Well, if you think about something simple 25 00:01:39,590 --> 00:01:43,850 like the weather, it's not actually that simple. How do you even get 26 00:01:43,880 --> 00:01:44,270 the weather 27 00:01:44,270 --> 00:01:49,270 if I asked you to figure out the weather without using some sort of website or tool? 28 00:01:50,660 --> 00:01:53,570 Well, in this particular case, open weather map, 29 00:01:53,780 --> 00:01:58,100 they have access to over 4,000 weather stations across the globe, 30 00:01:58,580 --> 00:02:03,580 and then their data scientists will take that weather data and look at the 31 00:02:03,680 --> 00:02:08,680 satellite images and process that data in order to figure out the weather and 32 00:02:08,720 --> 00:02:13,220 predict the weather for each city in the world. As you can imagine, 33 00:02:13,220 --> 00:02:16,610 that's going to be really resource-intensive and it's going to require a lot of 34 00:02:16,610 --> 00:02:21,440 employees and also server maintenance and electricity costs, right? 35 00:02:21,890 --> 00:02:26,000 So for all of that hassle, if they're going to provide this data for you, 36 00:02:26,270 --> 00:02:29,900 then it's reasonable that you should be paying for it, right? 37 00:02:30,380 --> 00:02:31,830 Essentially you can see a lot of 38 00:02:31,940 --> 00:02:35,660 APIs as a way of selling data. 39 00:02:36,140 --> 00:02:40,820 If you own some sort of privileged piece of data that you are constantly 40 00:02:40,820 --> 00:02:44,720 updating, or you are actively generating, for example, 41 00:02:44,720 --> 00:02:48,320 weather data from satellite images or financial data, 42 00:02:48,650 --> 00:02:52,940 then it's reasonable that you should be charging for this data 43 00:02:53,180 --> 00:02:57,260 especially if somebody is going to rely on it heavily in order to build a 44 00:02:57,290 --> 00:03:01,030 commercial app or a company. But luckily, 45 00:03:01,240 --> 00:03:06,240 most of these APIs provide a free tier that allows you to test out the 46 00:03:07,500 --> 00:03:08,333 application. 47 00:03:08,610 --> 00:03:12,150 And if you are somebody who's just learning the ropes then it doesn't make sense 48 00:03:12,150 --> 00:03:12,983 to charge you. 49 00:03:13,290 --> 00:03:18,090 It only makes sense when your application or your service has a lot of users. 50 00:03:18,480 --> 00:03:22,860 And then you start going into the paid tiers. Now, 51 00:03:22,890 --> 00:03:27,180 how do you prevent people from abusing this free tier? 52 00:03:27,210 --> 00:03:29,880 Because anybody can say, well, I'm just learning, you know. 53 00:03:30,360 --> 00:03:34,260 You can be somebody who's running a 1000 employee company 54 00:03:34,260 --> 00:03:36,900 and you could claim that you're just learning. 55 00:03:37,800 --> 00:03:42,240 So the way that they prevent people from abusing their service is through 56 00:03:42,240 --> 00:03:44,640 something known as an API key. 57 00:03:45,180 --> 00:03:50,160 And this is almost like your personal account number and password. 58 00:03:50,730 --> 00:03:55,730 This is the way how the API provider can track how much you're using their API 59 00:03:57,210 --> 00:04:01,110 and to authorize your access and deny you access 60 00:04:01,110 --> 00:04:03,720 once you've gone over the limit. Now, 61 00:04:03,780 --> 00:04:08,160 different API providers tend to have different ways that you can authenticate 62 00:04:08,160 --> 00:04:09,210 yourself with them, 63 00:04:09,630 --> 00:04:13,350 but most of them involve some sort of an API key. 64 00:04:14,100 --> 00:04:18,149 In the next lesson, I want to show you how we can implement the open weather 65 00:04:18,149 --> 00:04:19,140 map API, 66 00:04:19,500 --> 00:04:24,500 authenticate ourselves with an API key that we generate, and get the live wather 67 00:04:24,550 --> 00:04:28,500 data. So for all of that and more, I'll see you on the next lesson,