How To Use API's with Visual Studio, C#, ASP.Net | Aaron Craig | Skillshare

How To Use API's with Visual Studio, C#, ASP.Net

Aaron Craig, Helping Everyone Learn the Best They Can

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
18 Lessons (1h 45m)
    • 1. 1 - Course Intro

      1:55
    • 2. 2.1 - API Overview

      5:02
    • 3. 2.2 - JSON Overview

      6:22
    • 4. 3.1 - Installing Visual Studio 2017

      4:18
    • 5. 3.2 - Installing Postman

      4:55
    • 6. 4.1 - Pokemon API Docs

      4:55
    • 7. 4.2 - Sending A Web Request

      8:06
    • 8. 4.3 - Creating The Pokemon Object

      12:45
    • 9. 4.4 Using The Pokemon Data

      6:31
    • 10. 5.1 - Become A Giphy Developer

      3:00
    • 11. 5.2 - Exploring Giphy Docs

      6:34
    • 12. 5.3 - Getting Gifs

      9:55
    • 13. 5.4 Showing Off Some Gifs

      5:03
    • 14. 6.1 - Exploring The YouTube API

      7:56
    • 15. 6.2 - Using YouTube Data

      13:14
    • 16. 7.1 Adding Headers To API Requests

      2:05
    • 17. 7.2 - OAuth2

      2:04
    • 18. 8 - Outro

      0:41

About This Class

APIs are the backbone of building rich, engaging applications. But they're not always simple or easy to use. We're going to walk through how to use real APIs like Giphy and YouTube, get their JSON data, and display in our web application.

If you've ever wanted to learn about APIs, how to use them, or even just how they work, this course is for you.

We'll be using all free software, so you just need this course. We'll be using Visual Studio 2017, C# as the programming language, and ASP .net MVC as the architecture.

Transcripts

1. 1 - Course Intro: greetings and welcome. My name is Aaron Craig and I will be your instructor for this course. This is a course focused on getting into a P ice quickly and efficiently. So we're gonna be using visual studio specifically the A s p dot net MBC model. But it will work with any C sharp product you want to do. There may be some tweaking, but if you want to use C sharp to access AP eyes, then this is the course you want to be taking. So we're gonna be looking at three different AP eyes and using them all throughout this course. So we're gonna be looking at the Pokemon database ap I giffey and YouTube. So we're gonna register to become developers in two of those, and I'm gonna show you how to send requests, get the data, parse it, creates C sharp objects and then actually display and used the data that we received back from those AP calls in a useful and meaningful way. This is gonna be a highly focused and quick course, so I suggest that you know a little bit about html and see sharp, but I'm gonna walk you through each step of the way. And if you get confused at any point, feel free to reach out with a question or message me personally, and I will get back to you quickly. AP Eyes are the backbone of transferring data around Internet, especially if you want to build your own application. Whether that be mobile desktop or a Web app, they are essential to know how to use. And unfortunately, a lot of times they're not intuitive. They are all different, and they can be fairly confusing if you don't have much experience. So I'm gonna walk you through step by step three different AP eyes. Looking at the documentation showing you how to learn to use an A P. I not just teach you how to use them. So by the end of this course you will know how to use an A P. I find a new one. Register is a developer and be on your way to making your applications a reality. 2. 2.1 - API Overview: So the first thing that I want to do is talk about what a p I is to make sure that we're on the same page, that we know what it is, how it works. That way. We're not confused when working with them. So it stands for application, programming, interface and application ca NBI a very wide term so it can include anything from databases online to somebody setting up a website that has some information that you can access. It doesn't have to be a big application like Facebook. It could be something very small and very specific. We're gonna be working with three different AP eyes and they are going to be a Pokemon database interface, the giffey database interface and the YouTube ap I so we're gonna be calling different requests to each of those and those air different applications And the way that that actually works is you put in a URL request usually called a get request g e t. With the information that you want to get back. So here is the pokey ap I the rest ful Pokemon, a P I and rest stands for representational state transfer, which isn't important just know that most AP eyes on the Web are rest ful in the sense that they all maintain the same way that they work and what they give back to you. So if we want to get information from this AP, I, what we do is we put in this address and then we pass in the information that we want specifically. So if I type in Pokemon Slash and here they tell you how to use it so you can put in a number. But you can also type in a specific pokey month of my type in Peak, a Jew and I press submit. This is going to go out, fetch that data and come back with all of this information about that Pokemon in Jason Format and Jason is JavaScript objects notation, which I'm gonna talk more about in the next video. But just know that that's how you get most information, especially with a P I calls because it's small and it's quick and it is universal at this point. So it's easy to work with across many different platforms, and it's going to be the same across most AP. I calls so an A P I is a way that a application can set up other people accessing their information. It is a fantastic form, and it's how information is shared across the Internet. So most companies have an A p I that you can access. If you want to learn about movies and you want to pull down movie information, making a website or an application, you're probably gonna want to use the open movie database that has a P. I calls for it, and you can get information about movies if you want. Whether you can do that, if you want the pH of the water in your local area, there's a P. I call for that. You can use a P eyes with Facebook and instagram and Spotify. So if you want to build an app or a website or whatever and you want to get information from one of their websites, then you use their AP eyes. It's for developers to use to get information. Now the type of information that's available is completely up to the developers of that AP I. So if you are trying to work with Facebook, they may severely limit what you're allowed to get from a user without express permission or you can't touch their friends or things like that. They get to choose what you're allowed to get and what you're not allowed to get, so that's up to them. And also really important is the documentation good documentation for an A P. I is essential. If you run into an A P I that doesn't have good docks, you're gonna be doing it. A lot of Google searching the ones that we're gonna be using will have fantastic documentation. And I'll show you how to read those and then implement them in pretty straightforward ways . So if you want to use an A P, I definitely check out their documentation first. And if they don't have good documentation, I'd look somewhere else, if at all possible, because when using a P eyes, you want to know what it's supposed to do and what you're supposed to get back. Otherwise, it could be very difficult to use correctly, So that's an AP at in a nutshell. Get information from somewhere else in specific format, usually Jason, which then you, as the developer of whatever you're developing, get to parse input where you want so We're gonna be using three Ap eyes throughout this series and I'm gonna be going over each one as we get to it. And hopefully, by the end, you will be pretty much an expert on how to use rest ful AP eyes. 3. 2.2 - JSON Overview: So when you use a P, I calls 99% of the time you're gonna be getting back, Jason, which is JavaScript object notation. It is a universally recognized and used way to transmit data across the Web in a very compact and quick way. It is a little confusing at first. The first time I looked at Jason, especially if it's not pretty, which I'll talk about that in a minute is very intimidating. It is confusing, and I was completely lost. So I'm gonna take you through what it is, why they use it and how we're actually going to use it in our programs. So again, I'm gonna show up our 1st 1 that we're gonna be using the Pokemon AP because it's awesome. So this here, that you see, is Jason. It is a way of having keys and values in a human readable format that can also be interpreted into other objects and classes fairly easily. So for the most part, it's a list of different kinds of keys and values. So here we have a list of abilities a list of forms, game indices, held items, etcetera, etcetera, some of these air empty but some of them are not an inside of them. You can see here that we have a game version and then inside of there, we have another list of version. So all of this is Jason. It's the way that the data is represented and transmitted. And over here, I'm gonna talk more about this website specifically because it allows us to translate Jason and to see sharp classes, which is the language that we're gonna be coding in. And it's fantastic. So if I want what I did was I copied this entire section and I pasted it into here. And this creates the C sharp class that we need to access all of them. So you can see here that it actually creates a class and they have the integer as an I D. And if we come back and look at this, you can see that this is an integer and it's an I D. And it's an indigent here of one. Now this doesn't tell you what it is, but it allows you to access what you get back, and it knows that it's an integer and you have different types, then you have the lists, which are very important. So we have a list of abilities which is right here. So we know that this is a list and there's different ways toe access, that. And if we go and we find ability inside of here, so we scroll up here's ability. But then we also have ability to, and you can see that because we have this right here. They are named the same, so it's a little bit trickier when accessing them. But that is this specific A p I and Jason response. Not all of them were gonna have the same names, and a lot of them are gonna have sometimes unhelpful names. But usually it is very descriptive and very helpful. So Jason is the way that you transmit the data. And the reason that it's used, like I said, is that it's small and compact. When you are calling to get information from a website, you don't want to be passing actual images. You don't want to be passing videophiles and things like that because that would take forever. That could be megabytes and megabytes or larger, depending on what you're trying to get at. Like if I wanted to do an A p I call to get every single Pokemon that has ever existed. And they actually sent me back the images of every single Pokemon that would take a very long time to do. But this Jason, it is just text. That's it. All it is is a string formatted certain ways, and we can get that back almost instantly. And then you can do things with the information that you have so inside of here we can see that we have information. And if we want more information, we can actually follow some of this information right here. So if I copy this pasted in, we're going to get back. Jason. And this is Jason. That isn't pretty. So here, this is formatted in a pretty way. This is pure Jason. How it would look well when you get it inside of code and then you have to translate it. But if we look at some of this, it's gonna be kind of weird because they've added in slash is because of the way we're accessing it through a Web browser and not through like an actual get call like we should be. Um, we can then use this information. Teoh Goto what we want. So this is the front default sprite for this Pokemon. If I copy this and that paste it, I can come in here and I can get rid of these extras. So if we delete slashes that shouldn't be there, we can then navigate to the image as a girl. And that you are Earl is just a string and weaken the place that into our application. And then we have this Sprite ready to go, and that will work for pretty much all AP. I calls that you get, we're gonna be working with Giffey and YouTube. They're not gonna be sending back the actual gifts in the actual videos. Instead, it will be in the form of Jason in the form of you URLs to this image to this thumbnail to this video. And then you use whatever you're using. We're gonna be using HTML and razor to then put that into our website and display it and make it function the way we want. So we can embed that video. We can make that picture a link to the actual website because we have the information where that link is coming from All of that data is transferred through Jason JavaScript Object notation. You're going to see it all over the place when you start using AP eyes. And like I said, at first it can be confusing. At least it was for me. So take some time, look it over, try to get familiar with it. But we're gonna be using it a lot in this course, so jump right in if you feel like you can do it. And if you feel like you can't jump right in anyway because I'm gonna walk you through exactly how to do it. 4. 3.1 - Installing Visual Studio 2017: So we're gonna go and install Visual Studio 2017. So if you've already got that, then go ahead and skip ahead. If you don't, I'm gonna walk you through the process because you actually install an installer. And then from there you choose the options that you want, and there's quite a few options, and there's a lot that you don't need. But there are some specific things that you need, so I'm gonna walk you through that. So let's jump into it. Go to Google or whatever you want to search from and type in visual Studio 2017 and from here, you want to choose the one that is not the ad because you're gonna want Visual Studio Community 2017. And if you're using a different year version, that's fine. 2019 is coming out. I think pretty soon, if you have an older version like 2013 that's fine to see. Sharp will work the same across the mall. There might be a few visual differences, but for the most part you should be just fine. So I'm going to click on free download, and this will give it a start eventually. So it's a small installer. So I'm gonna click on that and this will get set up, and this will walk us through installing the installer. So from here, there's a lot that there has to download and fetch and install. But once this is done, it's gonna open up a window that allows us to then choose what components we want to specifically install with visual studio. And there are a lot of different components that you can put on their, depending on what you want to do with your visual studio installation. Because you can do games, extensions, uh, databases websites. All of those could be done with visual studio, but you need to have components or packages installed to do them properly. So with that, let's choose the right ones. What we're gonna be doing is the dot net desktop development. So and specifically, we want to be doing sp dot net Web development as well. So this gives us C sharp and the airspeed dot net, and that's what we're gonna be using. All of these options are great if you want to do something with them, but we don't need to do them because we're gonna be doing dot net a sp dot net Web development and those are the two that we need. So go ahead and click install, and then this is going to take quite a while. There's about 7.5 gigs to download here, so this is going to take a while, so I'm gonna go ahead and let the video run through. But then I'm going to speed it up or chop it off when I get to the done part. So you composite and wait for me when you are done. All right, I'll see you on the other side. Oh, right. Visual studio's finish in selling on my system. And it took about 15 to 20 minutes there, so might have taken longer and yours. Or if you got a better system than it would have been a lot shorter, which is cool. So Might is picking up my profile, and yours might not. If you don't have a profile, you can create one and do that. It will save settings for you, or you don't have to. Don't worry about it. So I'm gonna go in and customize the look and feel of this really quickly to show you because I like setting it to do the dark theme. And I'm sure you have to do that. Mine doesn't automatically. But if yours doesn't, you Congar 02 tools and options and right here in the environment for General, you can choose the color theme I like dark because that works pretty well. And then if you have any other specific things that you like to change in your software than you can come in here and you can find it, you can change different sorts of color. You can change, Uh, pretty much everything that you want. You can customize it to be exactly how you like it. I am usually okay with how they've set it up, so I'm gonna leave it at that. And that's all that we need to do right now. So I'm not gonna make a new project. I'm not gonna get started on anything here because there's one more piece of software that we need to have, and that's called Postman. So let's get that up and running in the next video 5. 3.2 - Installing Postman: another piece of software that is extremely helpful when working with a P eyes is called postman. So I'm gonna download that and show you quickly why you're gonna want it in how to use the basics of it. So I'm gonna search for Postman, and it will be the first option here. Get postman dot com We open this up and it says makes Web ap I development simple, which it kind of does. So we're gonna download the app. There is a free version. You don't need to pay for it. So I'm gonna go Windows 64 bit download that started up should only take a second. It's not a huge file, it's only 64 megabytes and on my connection, it is already done. So I'm gonna click on that. So what postman is going to allow us to dio is query AP eyes inside of their software without having to write any additional code. And it's gonna give us back that information and allow us to play with it and then be able to save that as well in very useful ways. So here's postman. It's a clean, nice looking piece of software and what we're going to do with it right now is actually test it out. So first I'm gonna come back and I'm gonna search for the Pokemon A P I and that is going to come up with this. So what I'm gonna do is copy this section right here, because this is the actual get requests that we want to send. When we access the A P I I'm gonna put this in, and you can see here that there are a lot of different options and postman is useful for a ton of different Web development scenarios. We're gonna be using it in a very small fashion, but still very effective. So we put that in here. This is the actual place that we're gonna be calling the a p i. And now we need to tell it what information we want to get back. So it has an example here of Pokemon slash one, but that's boring. So let's do Pokemon slash 10 and I'm going to submit that. Let's make sure that it works and you can see that it comes through successfully. So I'm gonna copy this, and I'm gonna put it inside of here and this is what they get. Request Looks like. So now we can send it inside of here and it comes back with the Jase on that we would get It also comes out with a lot of other very useful information. So it gives us the status of 200 a. Okay, how long it took and the size of it, which is tiny. You've also got a lot of other information, like cookies, headers. You can change the way you're seeing it. So this is like the rod, Jason, and you've got the preview version, which doesn't really change much. I always look at it in the pretty view, and you can change what it's like here if it were to come back in a different format besides Jason. So this is extremely useful. And also, you can just click on this and it will load up a new search. You can send that and then you get this back and I can click on this sprite right here. Send once more and it will actually give us that sprite again. So it's really, really helpful when working with a P eyes because you can plug in the get request that you're sending and see if it's actually working properly. So if we come back to this 1st 1 and I would change this to give me the Pokemon, that is the thousands that has been made, which there isn't, I think there's only like 900. So if we do this, it's going to give us the detail not found in the status of 404 It cannot be found, so that is an error message and allows us to see that really easily. Then if we add something inside of here like an AIDS and misspell it, we're also going to get in for a four message. But this time it's gonna come back. And this is like the actual website that it has returned. Not Jason. You can see here that this is actual HTML because it thinks that we're navigating to the website and it's going to be like a error page on the website. So if you get these different kinds of errors, it's good to know what they are in that way, you can react accordingly to them. So post me and this fantastic I recommend you have it on your system when you are working with a P eyes of any kind because it is a quick and easy way to test them out, and it saves everything you've done. It keeps your obsession currently running, and you can also sign in and make an account and have access to even more features. But that's postman. We're gonna be using it throughout this course, so make sure you've got it. And with that, I think that we are all ready to start working with the Pokemon AP I inside of visual studio, so let's jump into that. 6. 4.1 - Pokemon API Docs: I've already talked about how important good documentation is and for the polka PD A the Pokemon ap I that we're gonna be working with in this section, they have fantastic documentation. So let's go over that really quick and make sure that we know how to do a pH calls what items are available and what makes documentation good as opposed to bad. So right off the bat, you can usually tell documentation is good when it is lengthy. You can see here that there is a lot of information here and a lot of examples, which is really the best thing you can help for when you were doing a P. I calls. You want a lot of examples to know exactly what you're supposed to be getting back. So to start off, they've got information about the A P. I fair use policy. They also have a slack channel, which is great. So if you have any problems, you could hit them up. Ah, lot of AP eyes don't have a slack team or a way to communicate with them very officially or quickly, so this is also fantastic. They've got rappers. If you need to know specific things about the way you are accessing it, and then they've got the resource lists. And these are all the different points of information that you can get with this Pokemon, a p I. So they have pretty much everything you could need to know about Pokemon. As far as I know, I'm not an expert, but I've played a fair bit of the games, and I think they have everything here. So they cover Berries and contests, encounters evolution, games, items, machines, moves, location spoken on and utility. And when we look at one of these, we can see that this is how we get this information. They also say where they get a lot of this information from like bulb Appiah, and that is also very useful. So they're pulling information from here. So if you ever need to go back and check things, you can definitely do that and they're citing their sources, which is fantastic. So this is a get request. This is the A P I that they're using version two and you type in slash Barre and then you give it a I D or a name, so every single berry they have is gonna have an I D. So if you want to specifically search for Barry, you can put in the name if you know it. But you also want to make sure that you know what the name is, because the name might not be what you expect it to be. So they have here the name for this is actually the Cherry Berry. So let's copy this open home in a new tab. And let's say we want to search for Barre slash Cherry Berry. If we submit that we're getting a 44 error, that's not the actual name. That's not how we're supposed to be doing it. So let's cancel that and do a submit. And now that is what we need to be using is just cherry. So the name that we want is right there, and you want to make sure that you are putting in the right information, and this information is actually in the order that it appears, which is super useful. So you come down here and you've got everything you need to know about this Berry. And if you want to know more, if you want to access more information about it. They give you the you Earl, which is the a P. I call to get more information about that. So here's spicy. If you want to know more about the spicy flavor, you've got this ap I called to do Look, if we copy and paste will get back the Jason and not pretty format. But you can see here that it gives us that information all about the spicy Barry and everything that we need to know about it and also has the girls to images about the spicy berry. So that is how you use this documentation. And the important thing to know is that every single AP I document docks is gonna look different. And that's why we're gonna be doing three different documentation examples in three different AP eyes because each one is going to be vastly different. This one is really good. It covers pretty much everything you need to know, and it has numerous examples for every single kind of thing that you need, which I love. So it makes things simple. It makes things easy, and it has docks for all of it, which is fantastic. So it also has the data types that you're getting back descriptions in the names of what it is. So that covers the documentation for Pokemon. Now, what we're gonna be doing next is actually start using it. So I've already shown you how to use Postman with this. So we're gonna jump into visual studio, and I'm gonna show you how to set up a web request to this a p I, and start getting information back. 7. 4.2 - Sending A Web Request: aren't so let's get working on a project that we can actually access The Pokemon ap I from inside of visual studio. So I'm gonna create a new project here during the file new project, and we're gonna be using the A s p dot net Web application inside of here. We're gonna be using M V C, which stands for model view controller, and that is going to allow us to have a separation of concerns and allow us to create a website that we can then call different ap eyes at. So I'm gonna name this Pokemon a p I. And if you have never used this specific, I guess template or you've never made webpages like this, That's OK, as long as you have a little bit of HTML experience and you know some c sharp, you should be OK if you have no idea what this is, and you have no idea how do you do HTML or C sharp. Well, then you can follow along, and I'm gonna try to explain it as best I can. But you might be a little lost unless you watched a couple of times just so that you know, so I'm gonna click, OK? And inside of here, we're gonna be doing M V c. I'm gonna click, OK? And this is going to scaffold the project and set up everything we need. So we're gonna have a lot of different folders for models, views and controllers. If you want to learn more about that, you can check out another course that I'm going to have up soon. And that will cover how to create NBC projects what it is and why. It's a great formula and a great way to do website development. So now that we're inside of here, we're gonna close this out and I'm gonna open up the controllers folder and open up home controller. And this is where we're gonna be putting all of the code to access the web. AP eyes, get information from them. You can see here that this is called home controller and this is also you can imagine. The controller part is taken out when you're thinking about it. So on a website, if you go to the website, this is going to be home. So if you want to go to index, you could type home slash index and that will return a view. The views are inside of here. You've got home and shared, and home has about contact and index the exact same ones that we have right here. So you could have each of those pages. And if we actually run this, you'll see that it has a default layout. It has a default look, and it actually has some functionality to be able to jump between those pages and do things on your website. We're just gonna be sticking to one page right now, But everything we do everything I show you will be able to be used pretty much anywhere that you're using. C sharp. So if you want to make a desktop application or a mobile application with Xander and using C sharp, all of this will be useful to you as well. You can see here that this is the home page you got home about and contact the application name takes us back home. Now, we don't need all of those things. I'm gonna delete contact and about and inside of use, I'm gonna delete the about page and lead to Contact Page that I'm gonna open up the shared folder. Good layout. I'm gonna take out these two lines 24 25 just so that those can be gone. So if I save all of this when I run it again, you'll see that now in the toolbar up top, we don't have those. It's more simple. That's just a home page. And I'm actually going to delete everything on this home page as well, because we don't need it. So there's that and that. And if we open up our index, our home page, we have all of this. I'm going to leave all of it. So now our home page will be completely blamed, which is what we want. No, for us to start accessing the A P I. We need to be using some additional libraries. You can see up top here that this is using different libraries, and not all of them are being used. The's mawr gray ones. They're unnecessary right now, so we can actually take those out because we don't need them. But we are gonna need some other ones, and we're gonna import them as we actually use them. So the first thing we're gonna do is create the class called Web request. And if you press space here, you'll see here that it doesn't exist. So if you go to this little light bulb, it'll ask you to use using system dot net. It will bring that up here automatically and then sells a red squiggly line because it's an invalid statement right now. But you can see that it changed color because it recognizes which library that it's from. So I'm gonna say this is a Web request called request and then we say let request dot create. So we invoke this function and here is where we actually pass in the called the request You are I string to the A p I that we're going to access. Let me do that inside of quotation will put a seven column right there, and that will make it no longer red squiggly. So we're gonna make sure that what we're using is correct in the way we're going to do that is by having an option right here, I'm gonna click on Pokemon one and we submit that. And now to test this, I'm going to use postman. And so I'm going to say right here we've got Get request Pokemon one if I press send, it gets the information status 200. Okay, we know this works. So I'm gonna coffee this. I'm gonna come back into our project. I'm gonna put it inside of these quotation marks and that is going to send the request just like postman is doing, just like we're doing on the website. It's gonna send that out before it's going to set it up to send it out, because then what we need to do is create a web response. We're gonna call this response, which makes sense, and it's gonna equal request, Don't get a response. And this is gonna be the function that actually sends it out, and it gets the response from the Internet. So I put some comments on these so that it makes sense create request to the FBI request off. So that means that this is now going out. So if I ran this, it would actually send it out. And we can check that by putting a break point right here by pressing F nine or double clicking or just clicking over here. And if we run this, it's not actually going to load up the page successfully because it's gonna pause right here at this break point. But we can look and see that we are actually getting a response back. Now, we need to have a way to filter that response because right now what we've got are these variables. We've got request and response. So if I open up response right here, you can see that this is a system dot net web response and it is a application slash slash Jason. So this is the kind of data that we're looking for. It is a get, and this is the response. You are a you are I right here and then we can't look at it very easily because it's it's still in that response format. But this is a successful request to the Pokemon. AP I We have sent that out. We have gotten a response back. It has all the data we need. We just need to have a way to parse that. So let's do that in the next video 8. 4.3 - Creating The Pokemon Object: So we've got a response back from the server now. We need to parse it out so that we can actually access the information in a way that makes sense. To do this, you have to do several steps and the steps don't make intuitive sense. Which is why I think this is so complicated in a big reason why I'm making this course in the first place. Because when I have to first go through this, I spent many hours doing research and being frustrated because there's a lot of steps and it's just not easy like it should be. But I'm gonna try and explain these as we go, so hopefully you will have a much easier time figuring it out than I did. The first thing we're gonna need to do is call response dot get response stream. So this is a function that is going to return a stream of information back to us. Now we need to save that, and this is specifically returning a system that I o dot stream, which we're not using it. So we want to come up here and say we're using system that I owe and begin to say we're using the I O and then we have access to all of those. So I say stream, uh, just call it stream that is now correct. That is loaded in there, and that is what we're getting back. So get back response stream. Now we have that. Now we need to filter that out because the response dream that we're getting isn't human readable, and it doesn't really allow us to do anything with it. So we need to do something special with it. That's called Stream Reader. It's gonna call this a reader we're gonna say equals New Stream reader. And when we instead treat the stream leader, we give it a stream to parse to do information with. So we're going to stay stream. So we hand this into here, and that is going to give us a much easier way to actually access this information, so make it accessible. Next up, we need to turn it into a string because right now it's just a stream reader. We wanted to be like a string so that we can access it easily and then converted into a Jason object. So to do that, I'm gonna say string and I'm gonna call this, um, response from server. I'm gonna say reader dot read to end. So this is going to take all of the information in our stream reader and read all of it and put it into this one string right here. And that is going to be Jason. That then we can access using Jason Insider C sharp. So put into string, which is Jason formatted. Now, if we actually run this, we can look and see every single one of these things in exactly what they're doing, which might be very helpful for you. So this is not going to load up because it's going to hit this brake point right here. So now we have this request response a stream and reader, and you can see what each one is, which is very helpful. And you can then see that this response from server is finally the Jason that we want. Now. It's not pretty, and it's not legible, but it is the Jason that we want back from it. So each one of these is doing a specific task to make it so that then we can get that Jason back and all of this goes through extremely quickly. Uh, I know there's a lot of steps here, but it will fetch that data almost instantly and you'll have it ready to go. So once we have this, we are almost ready to do everything we need to do. There's two things left. We need to do something called the J Object, and we don't have it yet. So if you type J object, go over the light bulb and say you're using Newton's soft dot Jason dot leak. This will allow us to have Jay objects, which is a way of parsing Jason Data. So I'm gonna call this first string, and that's gonna equal J object dot parse. And the thing that we're parsing is this string right here? So we passed that in, and then that is going to turn it into a J object. Now a J object is adjacent object that is much more readable, and you can actually do stuff with this information. So if we run this and we take a look at this parsed string J object variable, you'll actually be able to see the information in fairly readable terms. It's not easily accessible yet but you can see it and you can actually play with it. So we've got this. It's loading up. Getting ready. Perfect. So now if we look at Parts two String so we can look at the whole thing, doesn't its response from server right here. This may not look much different, but we can actually come in and we can look at Children tokens so we can see exactly what's here. So we know that there's forms, abilities, stats. We have the name right there. All of these things. We can come in and weaken access, and we can look at them now. Like I said, they're not easy to look at yet. And you can't just se parsed string ability or parse string dot name because of the J object, and it has to be used in a very specific way. But what we want to be able to do is something like that. We want to be able to say this Pokemon dot name and then put that on our website, our application or wherever we want it to be that simple. And it can be I'm gonna take you back to a resource that we used called Jason to see sharp . You type that in and this is going to be the very first result that you get. This is a fantastic website and hopefully it is around forever. It allows you to paste all over Jason in there and get a C sharp class that Then you can convert your J object to and then access it like any other C sharp class, extremely, simply and easily. So how do we do that? Well, we need to pass it in the Jason that we want to make a class of. Let's go back to here and inside of our debugging or inside a postman. You check out this response from the server, copy it, come here and paste it in and you can paste listen from postman as well. So this right here you could paste this and it will be exactly the same thing. So I'll do that and I'll show you look a lot nicer. But it will come out exactly the same cook on just generate. And it will generate all the classes that you need to be able to access this Pokemon perfectly. So this is actually Pokemon form and each different AP I call you do is going to need a specific model is what we're gonna call it. That looks like this. So what I'm gonna do is actually come back Texas out of this. And I'm going to say I want just Pokemon for now. So I'm gonna generate this again, and it doesn't look too different. Although I'm sure there are some things different. So I'm gonna copy this, come into here and close our project. And what we're gonna do is we're gonna right click on the model folder. We're gonna add a new class. This is gonna be a C sharp class, and I'm gonna name it Pokemon. I'm being that specifically because that is what we are requesting. So we're requesting Pokemon one right there, and that's what we want So inside of here. I want to get rid of this public class Pokemon, and I'm gonna paste all of this inside of here. If you have any errors, make sure that you deleted that first class in that you're inside of the name space right here as well. Now I'm gonna name this route object. You can actually call it Pokemon. It gives it the name route object Because it's just like the root of everything. This is, uh, take a look at that. You can see here that this is the route object that has forms, abilities, stats, all of those right there. But this is an actual Pokemon class, so we want to give it that name, so I'm gonna save it. And now what we can do is take are parsed string and basically map it onto this model that we just created. And to do that, it's actually really, really easy. I say Pokemon now it's not picking it up yet. Pokemon dot CS It is inside of this name space and home controller isn't using that name space but doesn't know how to find it. So if we just type Pokemon that we activate using Pokemon ap, I'm module models right there. Now we have access to it. So I'm gonna say my Pokemon equals parse string, duck to object and we pass in. The object we wanted to map to is gonna be poking. And then we have a C sharp object that has all of the data off the Pokemon that we request . So if I say in my Pokemon don't and we go to just the properties you can see here that now we have access to all of them in a very simple and easy way to use. So we have the I d. Right there if we wanted to look at the moves because they moves dot and then we have a count of them. So remember, if we look at moves, really quick moves is actually a list of moves, which means that we need to say moves and give it a number. So the 1st 1 in the moves list docked. Here's the move. Here's the version group details. So there's move, and a lot of times you're going to come back and look at the actual model you've created. So if we go and look at moves, we can figure out exactly how to use it. So here is move. So we have the actual move name, so that is moved to So we've got move. We want to type in one more dot and it's gonna be name. And you, Earl, this is an actual string, and this is an actual string as well, so we can look at those. If I put in the name right here, right here, it's not gonna do anything. But if I type debug that right line and put this all inside of here import debug, using systems that diagnostics and we run this we're gonna now see that we have the name of the first move off the Pokemon that we have requested from the Pokemon. A p I. Let's take a look. We're paused here. Let's open up under view. We want to view the output and there it iss razor wind is the first move on this list for I believe it is bullets or that we're getting back. And we could have to take a look at that really easily to because if we open up my Pokemon weaken, see abilities, base experience forms game indices, height I D name is right there, bulbous, or this is now a C sharp object that you can access like any other seats are C sharp object , and you have access to all of its properties very easily, insistently. In the next video, I'm gonna show you how to pass this information into the Web page and then do something with it That might be, well, a little more interesting 9. 4.4 Using The Pokemon Data: So right now we have information coming back from the Pokemon A p I, which is awesome. But what if we actually want to do something with that? So I'm gonna show you have passed information into the web page and then access that, uh, inside of there. So if you've never done that before or if this is new to you, make sure you pay close attention and I will try to explain as best I can, But hopefully you do have some HTML experience, so we don't need this d bloodline anymore. So I'm gonna comment that out. We also don't want this brake point here. So what I want to do when we load up the index view is actually passed in the information of the poke month. So I'm actually gonna say I'm passing in my Pokemon along with this. Now, if you had a list of Pokemon, then you could create a list and passing that list as well, and that would be fine. But right now we're just getting 10 come on. Of course, you could create a four loop and go through into a huge ton of Web requests, and that would be a way to do it. If you want to display like the 1st 20 Pokemon or something, that'd be an easy way. So inside of index, now we have a blank page. What we need to do at the top is tell it that we're passing in the Pokemon model and we do that by saying at model lower case and we say it's going to be Pokemon, but it doesn't know that Pokemon is a thing. So we need to actually say it's Pokemon AP I the name of our project don't models dot and then we want to say Pokemon, and that is what we're passing in is we're passing in this Pokemon CS object right here. We could pass in specific things like if we just wanted the sprites, we could do that, but I want to pass in all of the information, just in case we need more of it. So we say we're passing that in and then inside of here. We now have access to it. So if we want to add an image left bracket, we say image. We say the source is equal to normally. This is where you put a u R l of some kind. But because we're using C Sharp and we've passed in this Pokemon model, we can instead say at model with a look with uppercase m docked sprites because that's where the images are. And now let's do front default. Close off this image tag and let's give it the name of the Pokemon here as well. Same thing that model Doc name, because that's where the name is located. And if at any time you're unsure what you could do very easily has come in and do the request inside of Postman, and then you can look and see where these things are and there's name right there. You can also look inside of your Pokemon C C. Sharp class and see where things are. So with that, if we run, this will now be able to see the image in the name of the Pokemon from the data that we've gotten from the Pokemon, a p I. And if you haven't figured it out yet, the strength of a P eyes is that the data you get back the format, it's always gonna be the same, not the data necessary, not the content but the type in the names, all of those air gonna be exactly the same. Here we have bullets or with his sprite. Now we don't have to change this at all. You want to change anything on here? We just have to say, Let's get a different Pokemon. What's the 534th Pokemon? We do that and it won't matter because our model is always going to work for the Pokemon Jason data that they're sending back to us. So, you know, change the sprite, it'll change the name. But if you have it formatted in a certain way, if you've got your website your applications set up, then this will work perfectly. As long as the A P I request goes through successfully that IHS So that is how you use an A p I. So if we had a list of Pokemon in here, they could do a four loop inside of here with razor and a showcase, all of them that we wanted to pass in. You now have access to every bit of information for Pokemon that you could ever want, and you can access it quickly, easily and make more classes as necessary. So this is the Pokemon model. But if we were to come in here and change it to bury and press send, well, this is gonna look a lot different. So if we were to copy this from here and go to Jason to see sharp and paste this in, this is gonna look a lot different. I would rename the route object to bury, but you can see that it's a lot shorter. It has different names and everything. But any time that you look for a very any time that you call this a P I to get a very back , the names will always be the same. So you can always display all the sprites, all the names you can set up the HTML and design your website and then just fill it in with the information that you get back. And that is actually a big part of why they made this Pokemon a p I, and why they make a lot of AP eyes is it allows you to maintain your website, your application, whatever it is by just having a P. I call. So it's just one database that has to be updated. They say here that there's, you know, there's hundreds of Pokemon websites and whenever anything changes, they all have to update their own databases internally, and it takes a long time. But if you're using this Pokemon a P I, you don't have to do anything because it will automatically fetch new information. Fetch new Pokemon from their A P I calls, and you don't have to worry about it, which is totally awesome. So that is using the Pokemon AP I. It's open. You don't need a key. There's no authentication. But that's not the case for all AP eyes. So in the next section we're gonna be looking at how to use Giffey because you actually have to sign up and use a key with them, and I'll show you how to do that. 10. 5.1 - Become A Giphy Developer: in this section. We're going to be using Giffey as an example for AP eyes. The reason we're gonna use it was giffey is that they requires toe have a key now that is different than what we were doing. We didn't need to have any authorization at all before and with authorization. You have to add in some information to your request to then make sure it works properly. And Giffey is a fun little website that allows you to access gifts, share them whatever you want to do with them and it's a lot of fun. So I figured that we would use it. So the first thing we need to do is become a development type giffey ap I into Google, and it's gonna be the first option. Developers don't giffey dot com and inside of here you can log in. But what we want to do is create an app. So the first thing you have to do is be logged in, though, although if I click on create nap, you can then log in or you can create an account. So I'm gonna cook on joined giffey because I don't have an account and I am going to pass in the email address in passing the name with some letters attached to it. Give it a password and I'm gonna click. Joined. This will authorize take me to my dashboard. And now I have a developer account. So I want to click on, create an app, give it a name. I'm going to say test course, and I'm not gonna give it an apt description. This will make our test course our app right here. And this is the a P I key that they give to us. So we're gonna need to use this inside of visual studio to authenticate who we are. And they know exactly who we are. The reason that they hand out keys and that there's authorization for AP eyes is that well , they are giving you this information for free. They are allowing you to use their hard work that they've gathered all this information and they want to make sure that they know what you're doing with it. A lot of companies will have specific rules and limitations on what you're allowed to do with their A p I key. So using it, they're gonna know that it's you. They can monitor you and then they can cut you off if you're not following their rules. Now for Giffey specifically, this a p I key is really limited. You're not gonna make an application using this key because there's only a couple of requests that you can do per minute or per hour or something like that. So if you had hundreds of people using a website or an application using this, that wouldn't work at all. If you want to do that, you need to request a production key, and that will be a lot more information. And you have to actually show them what you're doing and and why you should have it. But we're not gonna do that. We just want to use this a p I key inside of our app to get information from Giffey. I'll show you how to do that, and we're going to explore the documentation in the next video 11. 5.2 - Exploring Giphy Docs: So now we have an A P I key. Let's figure out how to use it. Let's click on docks up here and look at the documentation. Now, a big reason that I chose Giffey is that they have really good documentation, which again is super important. So you can see here that they've got a p. I highlights the sticker ap I upload a p I. So you can create nap that does basically everything their website does. They're letting you have all of that power, which is totally awesome. Now what we want is actually down here inside of technical documentation, the path names inside of an A p. I should be very useful both for when developing it. But also when using it, you can see here that gifts search. You shouldn't understand what that does just by looking at the path name trending, translate random. You've got stickers, search, trending, translate and random, and then you can upload gifts as well. So how do we actually do that? Well, if we come down to the search endpoint, which is the one we're going to implement inside of our application, we use the host here and this is the path that we give and the type is get as usual. And then there are all of these parameters which we're not really used to in the Pokemon AP I we just passed in exactly what we were looking for. There wasn't very many options. Now this one gives you more options. The 1st 2 are required the A P I key and the query itself. But everything else down here is optional. When I would recommend not changing is the Jason. You want it back in Jason format. But here you can change how many you get back. The default is 20. You can set an offset which if you're doing pagination or you know they'll only allow you to return so many. Then you need to go to the next page to start displaying mawr. So that makes sense. You've got rating and you've got language right here. The supported languages. They show you right here, which is important. And these air actually pretty much standard all the way across. But you always want to make sure if you want things back in different languages. So that is the search in point, which is what we're going to be implementing. So up here we also have sample responses and a sample call. So what I'm gonna do is copy this sample call and we're gonna break it down inside of postman. So I'm gonna make a new tab here. I'm gonna place this year and press send and show you that it's not going toe work. So it is a 43 forbidden because we don't have the right credentials. So let's take a look at this. I know it's kind of small, and I apologize for that. So I'll talk about each one of these here. So we have the gifts search. So this part, we know it is familiar. Then we have things that may not look a smelly. We have a question mark followed by Q equals funny plus cat. This is a search query, a search string inside of a girl. It's how it's formatted. And so when you have the query that you're trying to pass in, you give it a question mark. Q. Specifically is for Giffey right here. You see that they have Q. So you have to tell it that Q is equal to something, and here Q is equal to funny cat and a P I key is equal to your A p I key. Well, that's not my a p I key, which is why it didn't work. So if I go to dashboard, copy this a p I key pasted inside of there and press send it will now give us this information back and it gives you a lot of information. Giffey gives you lots of different ways to display the gifts, which is really fantastic if we come down here to original you, Earl, we have with height size frames, MP four and before size. All this is great. So if I click on this URL and I click send postman is actually going to go out to that URL and fetch the gift that the 1st 1 is. So this is the first gift that we got back when searching for funny cat using are a picky So postman takes a second but then it loads it up and there it is. So let's double check that if I go to Giffey and I search Funny cat, what is the first response? That's it right there that matches. This is exactly what we got back, and that's exactly what we searched for. So that makes total sense. Now. If we want to change this at any place inside of here, we can actually add in more of those parameters by having him and a symbol and following this exact same format. So after the A P I key, let's add in. Go back to the doctor. The quick technical documentation Let's add in an offset so it offset is default zero. But let's add in an offset type in and the ampersand symbol offset is equal to one. So let's take a look. You got the I d. Why we're not remember that. But if I press send, we're going to see that this changes and you can see the I. D is now different. And so if we come down here to original and we click on that, this is now going to be the 1st 1 in an offset of one. So we're changing which ones we get back first. And if we take a look at this inside of here, we can come back and see. This is the 1st 1 here. So if we were to do an offset of 100 we would basically be scrolling down 100 images and starting at the 1/100. So that is how offset works here specifically, which is pretty cool. Now, what we want to do is put this inside of our C sharp project and then be able to use that. And we're gonna do that by basically copying this right here and putting some of these copying this one right here and putting the A P I key the search query in the offset as variables that can be changed when the user searches. So let's do that in the next video. 12. 5.3 - Getting Gifs: let's get giffey up and running inside of a project. So it's going to file New project were named this one giffey a p I. Same thing NBC create that Let visual studio scaffold. That and what we're gonna be doing in this video is breaking down the parameters that you can pass into the giffey ap I into variables so that you can have all of them in there all the time. But if you ever need to change them based off user input, where you're redesigning your application, you can do that very easily and quickly. So let's go through and do the limited before. So I'm going to delete about and contact open up layout given of those two Open up index, delete everything inside of there basically and open up home controller and get rid of those two. Okay, that takes care of those things that we needed to change. So we're gonna dio almost the exact same thing that we did before, except we're gonna be adding some parameters and some variables to this. So what I'm actually gonna dio is copy are other code that we have and put it inside of here. So This is the exact same code that we used for the Pokemon ap. I So we need to import some of these using statements. So we're using I O. And we need Jason. Okay, so that brings all of those in. That's all of our using. Now we can get rid of the ones we're not using. And now what we need to do is change this, but also create variables that we can change as necessary. So let's open up, Postman. I'm gonna copy from here, and I'm gonna paste it right here. No, we want to put each of these perimeters as an variable that we can alter easily and quickly . So let's go back and take a quick look at all of the parameters. So we have a P I key and query. Those two make sense as they are required. We have to have them. I'm gonna say string a p i g equals Let's pull this out. So our a p a ki ends racier before this end and after equals. So in quotations. Put that there. And now what I'm gonna do is actually delete right here. I'm gonna put quotations here and quotations on that side. I'm gonna add a plus and I'm going to say a p I key and then plus on that side. And now this is our a p I key. So if it ever needs to change, you change this variable right here and makes it very quick and easy. Now, Like I said, this should never be done at least as long as your project is through source control or anyone else is gonna be looking at That's not on your team. You never want your a P I key to be public. So to make it not public using M V C specifically, we can add a dot config file and then pull things from that. So let me show you how to do that really quickly because you definitely don't want to be sharing. You're a P I key. So what we're gonna do is open up the web dot com fake this bottom one down here, the much larger version of web dot com fig and inside of app settings were actually gonna type in file, and it's gonna give us an equal here, and we're gonna put in where we're going to store our A p I key. So to do this, you have to give it the actual route relative to where this file is located. So it's going to be Donta slash Well, first, let's create the file. So it's gonna be called a P i keys dot config. So if I go to home and I create this, I'm gonna go new text document because you don't want to be anything. Give it that exactly. Name a P I keys and delete the the suffix of dot text and call it dot config and it will change this and then you open it up and then you put in the config file that you need, So we're gonna say app settings, and we're gonna give it a keep. So I'm gonna say, add key that's going to equal whatever name we want. So we're going to say giffey a p I key, and the value of this is going to equal what the value is. So lets go to home controller, grab this, copy it and put it inside of there, and you can add as many keys here as you want. But right now we just need one. I'm gonna save that and then inside of our home controller instead of saying this is the direct key. Now we're going to say ID equals system that led the configuration stop Web configuration manager dot app settings, brackets and then the name that you've given it. So we named it giffey a p I key. And that is a way of hiding it. Now, when you upload your project to the cloud, forget where your share it you are. Key is not going to be in it now to get your key to actually work properly, though, we need to make sure that the APP settings file is pointing to it. So let's find where the products are being stored and by default they're being stored under users. Your name source. So I'm gonna look for mine users, Aaron and then source and then inside of source. We've got repose, and these are all of the applications that I have. The one we want is giffey a P I. So what I'm gonna do is because I'm not using source control. I'm actually going to take the FBI file. I'm going to put it inside of here, and you can see that it's right here and the web dot config file is this one right here? And we need to go up one level to access this config file. So to do that, we're going to say it is dot dot backwards slash ap I config file on. The way to test this out is we can put a break point right here. We can run the project and if this comes back as an invalid request or if we don't see a P I key actually equaling what we want, then we know that we're not pointing directly to the right a p i config file whether we gave it a wrong name, wrong value around key or the wrong point. Then we know something isn't working. So I'm gonna go one through here. Let's take a look at a P I key inside of the bugger. It is correct. It is the value that we wanted to be. So we know this is being hidden properly and we can access it just like this Now, normally, you would not want it to be inside of your project, so you could put it like one up if it was on the desktop or something like that, and that would work perfectly. So with that aside, done, it's always good to code properly, even if it takes a little bit longer. With that aside, done, let's add in the rest of the variables that we're gonna want here. So string query equals funny cats. So we want to replace this with query so you can see exactly what we're doing here. We want to take the offset as well, just in case we need it. Offset, uh, put it equal to zero to start, and then you can change it anytime that you would want. So this plus offset and then you can add in the rest of them as necessary and change them when you need to. So with that, let's see if this is actually working properly. So it's come down to R. J. Object and put a break point here and run this. Now we have not created a model yet, so the Jason we get back, we don't have a model to map it to. We're gonna do that in the next video and then display some gifts on our home page. I just want to see if this is coming back properly, So response from server we have. Let's take a look. This looks like a bunch of Jace Jason with all the information that we need. So this is going through properly. It is accepting our A P I key and everything is working perfectly. So in the next video, let's make the model using the Jason to see Sharp website and show some gifts on the home page. 13. 5.4 Showing Off Some Gifs: Let's get some gifts displaying to show that this works and how exactly we put them on here . This is going to be pretty similar to what we did. But practice is a good thing when working with a P eyes. So let's first go to Postman and let's grab this. This is the normal gift search. I'm gonna take off this offset by one. We don't need that. That won't actually change anything. But I'm gonna copy this. We're gonna open up Jason to see Sharp again. Very valuable website. Pace it in there and generate. This will create our C sharp classes that we need to be able to work with it and come down to copy. Copied all in there. And then let's go to models. Create a new one. Add class. We're gonna call this, I guess. Just gift result. Uh, gift search result. I don't have good names. Your models take this out, Pieced that in rename route object. Call it just a gift and save. Come down here. We're going to the same thing that we did before. So we need Teoh import what we're using. So using giffey ap I module the name of our class. So we import our ability to use gift. And I call this my gifts equals first string, two objects. So we're gonna map this to the gift and then we're gonna pass this in now. We're passing in a lot more information this time around than before. Before, we just had one Pokemon with a little bit of information about it. But now we have 20 gifts that were passing in, which is a lot of information. And if we want to display all those, we're gonna want to use some looping technology. What we're gonna do is display all of them using a for each so inside of here. I'm gonna say bar item in the model dot data. Now it needs to be specifically model dot data because if we go and look at the GIF model, you'll see here that the main classes gift and then there is data, which is a list. So because it's a list we can use a fore each loop to get at it. So let's go ahead and just display all of these. It's not gonna be pretty formatted, but that's OK, so we're gonna say act item were using item because the for each loop this item is gonna go through every single one in the model dot data item dot images, I think, is what we're gonna wants. Let's go look up here. So here's images. So we got all of these ones to choose from. I'm gonna go with original so images dot original Let's follow that. So we have original, which is where is that original? Right there. 1 60 has a lot of lines here. Then we have all of these strings we have the URL with and before all of this. So we want the original. I'm gonna do just you are. Oh, so this is gonna be the original size off the gift, so it's not going to come out looking very organized or pretty, but it is gonna come out showing all of these gifts on our website that we're using from their A p. I so wala. Here are all of the funny cats that we're getting right there. But I think it would be a lot cooler if we came in here. That's get rid of that, plus that Stop it and I'm gonna say peek a choo Instead, people choose Pokemon we worked with Welcome on First, let's make sure this works so we can change our query just like that. And now let's see what shows up when we do that. Here we go. There are all of the gifts for Peek a choo that are popular right now, So that is how you use Giffey. You can see here that now you can very easily take this information and build an application that uses gifts. And it's fun. You can sort through it and allow users to search. No problem. You'll also learn how to hide your A P I key, which is a very smart thing to do. So that's awesome. That's using giffey, which is good now. We aren't quite done with this Siri's yet, because there's one mawr AP I that I want to explore something that you will probably work with in your time because it is so massive and so popular, and that is YouTube 14. 6.1 - Exploring The YouTube API: So let's look at the YouTube AP I because Google is such a big company, they've got really good AP eyes for all of their stuff, but that also makes them much more complicated. The other ones we've looked at have been fairly simple. Google YouTube specifically is going to have a lot more options and ways to access their data. So they've got guides and samples over here which are actually really good. So they have a guide for how to embed their information into your website, which AP I you need to be using. They've got samples of how to do basically everything. So look at it, looking at it in all these different languages. But if we go to dot net, they're doing it inside of a council application, which is a little confusing and not that useful following along. The first time I went through this, it didn't help me at all. It was un intuitive and not what I needed. So I'm gonna show you how to do it the same way that we've been doing it inside of an NBC Web application, and hopefully that makes sense. And it's much easier to translate if you take it somewhere else, but you can still use c sharp in the same things that we've been doing. So what I really want to look at is the Google ap I explorer so inside of here, you can actually test out all of their AP eyes online and see what you get back with it, which is awesome. They've got dozens of them here, and the one that we want specifically is at the very bottom YouTube data a p I to get here , you can search for YouTube, a p I explorer, and it will be the first thing that pops up right here. And then you can find YouTube through there now, inside of here. There are a lot of different AP I calls that you can make it puts the ones that we've been doing to shame because there are so many options. So a lot of these you're not really gonna need and a lot of them you'll never use. So you want to figure out which ones you need exactly and get familiar with those. The primary one that we're gonna be working with is gonna be down here. It's gonna be YouTube search dot list. So if I click on this, we can actually play with this right here inside of the browser. So the first thing that's confusing is part their terminology doesn't make a lot of sense, but basically, you can ask for different sections of data, depending on the A P. I call that you're doing. So you need to set it literally to snippet because that's the way they've designed it is set it to step it. So that's what you have to do now. You've got all of these options as well. We've also got the up option toe authorize using a lost two point. Oh, which I'm gonna turn off for now. Oh, off 2.0, something I'm going to talk about after this section and kind of how people use it and when you need it. But if you're using anything that has to do with user data, then yeah, you're gonna need to use o off of what we're doing. You don't have to. So all of these they've got good descriptions of them. The one that we're gonna need is this Cue the parameter the query that you are searching for so if I search Pokemon, this is those the only two that I need. So I'm gonna execute without O off. And then right down here, you can see that the get request looks just like this. So this you should be familiar with looks familiar. Looks just like what we've used before. Your a p I key goes there and then this is the response that we get now. The response here requires again a little more work, but we can figure it out. The first thing is that you've got the thumbnails, which is probably what you would want to display. So here the thumbnails and three different sizes. Then you've got the kind of result that you're getting back. So there's YouTube search results. But then there's also YouTube channel I D and YouTube playlist. Those things are different, and when you're using them, you need to make sure you filter them out appropriately. Now, the thing that we really need is this right here this video I d. So, if I copy this, you can then search for just the video entity and it will be unique. It will be the thing that pops up. So I think it's this video right here, but that's not useful. And they don't really tell you this, but what you need to dio go to youtube dot com and then slash watch slash one more time and paste in that video I d. And then that will come up perfectly. So you can see here that this video is the exact same one that we just found. So by doing that by having a little bit extra information that you might have to do some Google searching on, uh, you can figure out exactly how to use that. So the video I d. Is the unique identifier for this video, and that's important to know. You probably want to actually show the thumbnail on your website and have that be like an embedded video that links to this. And that's something that you could definitely dio. Now, apart from that, you can change a lot of the options that you get because there are a lot of options here. Some of the important ones are gonna be things like ordering so you can change how they are ordered. That's something that you put definitely wanna have in there as an option. The page token is a little confusing at first, but if you come down to the bottom, it will give you a page. It will give you a page token at the very top. You see here that the next page token is this. So if I copy it when we come in, you can paste it there and I can execute. And now these results are gonna be different. So I click on this. It's got a completely different thumbnail because I'm on the next page and right now I'm just saying, Give me five results per page, so there's gonna be a lot of pages. And now there's also a previous page token so you can go through pages like that and then all of these as you think you need them, Definitely play around with them and look at them. This is the default search for YouTube, though The last one that you really get a lot is the amount that you're getting back so you can choose how many that you get back when you do a search. And that is in max results, so they only allow 0 to 50. So if we execute that it's gonna return now 50 video results and that is the docks that you've got for you, too, and they are pretty good. They're just not great there. Little confusing if you've never used them before, and even if you've used other AP eyes, they can still be pretty confusing. And that's one of the difficult things when it comes to using a P eyes. Even if you've used a dozen of them, the 13th 1 might be nothing like the others. You'll find different AP eyes because they're designed by different people in different people have different requirements when developing them, and sometimes they're supposed to be public. Sometimes they become public after the fact, so they're not designed to be easy to read. And sometimes people are just lazy. So having experienced with AP eyes is helpful. But every time you go into a new one, you've gotta have the mindset that you've got to relearn how to use the A P I because they're all vastly different with that being said, though, in the next video, let's make a Google account, get a developer key and put it into our project 15. 6.2 - Using YouTube Data: All right, So let's get started with signing up of Google and getting our key. So we're gonna search for YouTube data, a P I. And the data part is important because if you don't, you're not gonna land on the right page to follow along. So I should say YouTube and then data ap I hear I'm going to switch to an account that I can follow along with you guys much easier. So here, we're gonna click on guides, and the first thing you do is create a Google account. If you do not have won, the first link will take you there, and I would be very impressed. The second thing you need to do is create a project kind of Google developer. Consul, we're going to click on that and inside of here, we're going to create a project, and I'm going to create I'm gonna name this test product. It is gonna be tied to your Gmail that you've got. So go ahead and create that, and then it's going to go through that process that's gonna wind up a lot of information for you. And it might take a few minutes. You can see over here that it is going and it is done creating my test project. So there's my name and here the AP eyes that I've got for it. So right now there's nothing going on. I'm gonna go back to my dashboard. So what I want to do is get some A p. I is working on this, So we're gonna go back to enable a B ice search for you too, and enable it now, now that we have a specific project, it will enable it for that project. And you get enable as many AP eyes as you want for a project. So you can be accessing maps and books and YouTube and drive all the one project and they'll give you different keys for each of those. So we've enabled it, but we need to also create credentials for So I'm gonna click on that. We want to choose that one. Where will you be calling the A P. I from what we want to choose his Web server. Unless specifically you will be using javascript later on. We're only going through C sharp, which is gonna be on the server side. So we're going to do that and what data would be accessing is public data. So what credentials do I need? It sets it up for me. You can choose to restrict the key to only certain websites I p addresses that way. Even if somebody gets ahold of it, that can't do anything with it. I'm not worried about that. Right now. Someone's gonna click done and that we have an A p I key. So we contest this out. So, uh, I could rename this as course key, and you can change some restrictions on that. So, Allah, that is the key that we need. So I'm going to copy the key. That way we have it. But now we need to create a new visual studio project. So let's create a new one. And this one will be for accessing YouTube. This time around, Someone make a new project, call this YouTube a p A M V. C. As usual. And this time all I'm going to do is go into the View Home Controller Index and just delete all this so that we don't have to worry about it. Okay, let's open with the controller. And now let's set up that key. So I'm gonna say string, baby I ke and you should definitely put it inside of a file. That way it's not being shown off because YouTube will track every single call that is dug through this AP Yankee. And it will be very useful for you as a developer, but it must be very useful for them to keep track of. So you don't want other people getting ahold of this key. This one for me is just throw away. So I'm not gonna worry about putting in that config file. But I showed you how to do that in the giffey section, and you should definitely do that as a regular process so that your keys are not available for anybody who wants them. Okay, For the most part, this is gonna work fairly similar to what we've done before. So I'm gonna do the same thing. I'm going to copy all the work we did before. All right below. Here, paste that end now inside of here, this is going to look different. So let's lead all of this and then let's import all of the things we need here. So we need system dot net system Io and we need noone soft. Jason. Perfect. So we're all good there. Now, let's go back to the YouTube Explorer so we can actually access that from right here. So if we go to our dashboard YouTube data, we can go and trying to Ap. Isn't this explorer now? These are all of the FBI calls that we have access to, but the only one we need to worry about right now is the YouTube. Where is that Videos now, you tube search dot list. Right there. Okay, so the part has to be snippet, and we just need a query. So we put Pokemon as the query and execute with O off. We can get this right here. So we copy this and let's put it inside of here. Now take out the U your A. P i g replace that with a P I key. And then that should go through correctly. So let's put a break point in right here and run the product. So if it doesn't work, then we know that we're gonna get a specific kind of error. And with that specific air, we can go and then look up. What they say so. 403 is forbidden. 400 is a bad request and 200 means that it's working correctly. So we should get five results back from the search because that's the default amounts that we get back. So let's take a look at first string and it looks like everything is coming through correctly. So we can also look at the response from server and that came through wonderfully So that is working for the A P I call. So now what we need to do is the usual is create a C sharp object using our website trick. So let's go back here and it's copy this search Jason C. Sharp and put it in here now. One thing that I will say is that this gets a little more difficult when you're using YouTube AP I or just larger AP eyes. I have a lot of options because we're going to generate this class, but it's missing a lot of things that it could be, so it doesn't have an option for a video embed herbal video category. I d. All of this stuff. It's not in here, but if we were to start adding those things as filters as requests and parameters for the A P I call, it might change how much Jason were actually getting back and which fields were there. So an important thing to keep in mind is that this class that we're creating is on Lee good or at least only certain, for the query and snippet specifically for this ap I call. So you might want to make a comment of that. You might want to make a note of it somewhere. That way, if you ever come back and you need to say, Oh, I only want that if it's published after this date or I really do want to start having more page tokens in their things like that, you'll need to come back and regenerate the classes that you're used. Copy this. Good models, Ad class. We're going to say this is a YouTube search pasted in here. YouTube search spelled correctly. Okay, now here, we're gonna say you to search and we need to import are mud model that we're doing. So YouTube search will discolor. The search equals first string that to object you to search. We're gonna map that onto there and then we're gonna pass it inside of here, just like what we have been doing. So with that now, we can actually play around and look right here to see what's possible. So if I said search dot I know that there are items kind page token, things like that, which is great. So it looks like everything is gonna work fine here. So it's going to index. You can say that model and this is going to be, uh, YouTube, baby. I got models YouTube search and let's display thumbnails and titles of each one of the results that we get back. So for each far item in model and model is not going to work because it's not a list item. What is the list item in here? Let's take a look. The items is an actual list, so model dot items that will generate a way for us to go through in the for each loop. So we want to do image source item docked. Let's take a look. So we have item here and then step. It is the main thing that we want. We have i d for the specific item. If we want to embed it into our website, which we can dio. But we also have snippet and sniff. It contains the published at the Trial Channel I d. The title and the thumbnails. So we want thumbnails and inside of thumbnails you've got default medium and high and those air right here. So let's grab. Don't sniff it thumbnails dot my got you, Earl. And then beneath that, let's put in a p. And this will just say that item that snippet not titled Let's run this and see if we're getting YouTube data back successfully and displaying it Pretty sure everything's gonna work. And if so, then this is accessing one of the biggest AP eyes on the market right now and allowing you to do so much. So that's the thumbnail. That's the name of it. Looks like everything is coming through just fine. That's awesome. Okay, so that is the YouTube a p I inside of here. You've got a lot longer of, ah request to put in here. And there are a couple parts like the snippet which don't always make sense until you start playing around with them. And one thing I encourage you to remember is that this model is Onley good for the specific parameters that we've got. If you change the parameters, plug all that into postman or pull it from the A p I explorer and regenerate this right here. It won't change anything that you have already, but it will add new fields for you to use if you want to access them such as the next page token right here. We don't have a previous page token now, of course, we could add that you can create these yourselves, but it might also cause issues if you don't already have it there or if you were to type it wrong, it's not going to map it and correctly, so you can create these classes yourself. But I would definitely recommend using the website I've been showing you. It is quick and awesome and very easy. So that is using the YouTube a p I. If you have any questions about that or run into any errors, definitely let me know, because using these big AP eyes is awesome. But there are also issues and complications that come along with it, and the last thing we're going to talk about is other things that you should know wouldn't working with a P eyes that are fairly common. But I didn't want to address here. We didn't have a good example for them. So we're gonna talk about those next and how to make sure that you think about them when you're using a P eyes. 16. 7.1 Adding Headers To API Requests: one of the things you may encounter when using a P eyes is that they want you to have an additional layer of authorization or authentication sent with headers in your Web request. To do that in C sharp, you actually add headers inside of the Web request. Now, an example of this is you. To me, they have an A p I. You have to sign up, and it's actually kind of a hard process. To get a key, you have to show them what you're doing and have a website that is working so that they can test it out. But once you get it, you'll get a key in a secret, and you put them together in a secret way. And then you have to add that combination with the word authorization basic and your key, and you have to do that. Otherwise it's not going to work at all. So to do that inside of visual studio, what you can actually do is before you send the request off, you would say request dot headers dot ad and here you actually add the header that it needs toe have so we could say authorization basic and then you would add secret key right here. And by doing that, it adds it on front of it so that it's It's like your A P I key, but it's beyond that. It's another level of security, and postman can also do this. So inside of here you can add headers so you can add a new key in the value and giving a description so you can also use poster and if you need tohave headers and this is a really good way to test it, to make sure that it's working well. So that's something that you might encounter with AP eyes. It's something that I've run into with you to me specifically because I've used their A P I before and figuring out how to add that header took a little bit. So I figured it would be good for you to know, just so you have it in the back of your head. If you're using more AP Ice 17. 7.2 - OAuth2: Oh, off to is the de facto when it comes to security. When using a P eyes, Google has it, and you have to use it when you're accessing someone's data. And most AP eyes were going to require it if you're accessing anything personal or even just using their AP eyes. So it's gonna be different for every single kind of application you're making about how to implement it. But basically it is securing your application and authorizing you to access someone's personal data and a really great way to implement it. Is this article right here which I got to buy just searching how to enable a lot to 0.0 A s p dot net NBC. So this takes you through creating Loggins for Facebook, Twitter, LinkedIn and Google, and you do that by accessing their AP eyes but authenticating through oh, off to and it's kind of a long article, but you can go through it if that's something you need to do. The basics of it is you need to put http s and have an SSL certificate on your application , whatever that is, so that it is guaranteed to be secure and then they will allow you to access users personal data that way. So keep that in mind when you run into an A P I that wants you to use a loft to it doesn't have to be hard, but it is going to be something that you need to do. And it will take a few minutes, if not a couple of hours, to figure out if you're doing sp dot net, and we see a lot, too. Here is what you need. If you're doing anything else, the process will be different, so I can't cover them all. But I know that there are a lot of ways to find out exactly what you need to do and especially the guides from the A p I that you're accessing when it comes toe Google or Microsoft. If you're trying to use one of their AP eyes, I'm sure that they will have an example for what you need to do. And if that doesn't work, check out, stack, overflow and ask questions 18. 8 - Outro: congratulations. You now know what you're doing When it comes to AP eyes at least inside of visual studio using C sharp. I hope this course has been helpful. I hope that you've learned how to learn to use a P eyes, not just following me step by step, but knowing how to actually read the documentation, register as a developer and find the help you need when you get confused on AP Ice. And if you like this course, I hope you'll check out my other courses that I've got and that you will continue to support me on here. And I will do my best to support you through any questions, any messages, anything you have. I want to say congratulations again and get out there and make whatever you want a reality .