All right welcome back.
So this topic this section that we're going to talk about is one of my favorite things to teach.
It's really really fun for me.
And I know I say that a few times in this course but this is by far the actual favorite topic of mine
and it's really exciting to learn in my opinion.
We're going to talk about A.P. guys.
And the reason that it's exciting to learn is that it really opens up the possibilities for what you
can build.
You can make all sorts of amazing applications that use data from other applications or that rely on
other applications.
Basically you know you can stand on the shoulders of giants and and make some really awesome things
for that having to do a ton of work and do everything yourself from scratch.
So the subtitle is connecting with other apps.
And that's really the gist of all of this is what if we want to display a map or I want to get latitude
longitude data or I want to get weather data.
You don't need to go put out weather sensors and connect them to the Internet and then get that data
.
Someone else has done that and made it all nice and easy for you to understand and interact with and
then you just write code that uses that API.
So without getting too far ahead of ourselves API stands for application programming interface although
it's actually application program interface.
Some people say programming it doesn't matter.
But the idea is that it's an interface for programmers for code or computers to talk to one another
.
So I can write code like this code it's very small.
But this code right here is interacting with Facebook.
So Facebook has an API that allows me to get data from Facebook.
So we have it you know human interface when I go on Facebook myself and hopefully don't spend too much
time there but when I do that I'm looking at the human interface the HTML usually that I see it's rendered
to me nice wig out photos and colors and text and fonts and all that stuff.
When I want to make an app though that uses Facebook data so popular example would be something like
Tinder if you're not familiar with Tinder you're probably lying.
But if you're actually not familiar with Tinder Dating ish application that you go on sign up with your
Facebook account and it shows you people's photos you can kind of say yes or no swipe left or right
.
But most importantly to what I'm talking about here is that it shows you if you have any likes in common
with them.
So if you have any favorite movies that you've added to to both of your Facebook profiles or books or
music as well and a few other things and it also will tell you how many friends you have in common based
off of Facebook.
So that data is not just coming from the regular Facebook website like if I went on Facebook I could
find that out if I matched someone I could go on their Facebook page if it's public at least and I could
manually compare.
Do we like the same movies.
But of course that's not happening behind the scenes intender source code.
There's code that's connecting to Facebook's API and saying Hey these two people.
Well it's probably more like hey this person Nicole has matched with let's get their data and save it
to our database and then let's take cold's data that we already have in our database and compare them
.
But the idea is we're talking or tender is talking to Facebook and that's one example.
But API eyes are literally everywhere nowadays.
Pretty much every application you use.
So the term API is actually a broader term that refers to any type of code any interface that is made
for other code to communicate with.
So if we go on Wikipedia actually the definition the textbook definition I guess is in computer programming
an application programming interface.
So they use programming.
That program is a set of routines protocols and tools for building software and applications.
So that's very broad and that is basically saying it's any set of tools code routines that you can use
in an application.
So it could be a database API.
So that has nothing to do with the Internet.
It's just how you connect to a database locally on your computer.
It could be a video card API or a hard drive a hard disk drive API.
So those are kind of other non web based examples or when I was learning Java in high school I used
an API to to incorporate the graphical elements buttons and windows and stuff into my applications.
Really ugly Mario clone that I made and like solitaire I used an API for that.
So that is a different kind of context.
Typically what people mean when they refer to an API today is a web API which has its own section here
but that is a subset of API in general.
So API is in general any code whether it's a library a package or module a web API some sort of interface
to work with image analysis on a computer or a database.
They're all over the place so many different things that they do.
You can use them in your own code web API is are more specialized.
They have to do with web interfaces to other code or to other applications.
So for instance the Facebook API we talked about the way that an application gets that data is through
the Web through the Internet.
I am requesting that data from Facebook.
So just like when I request a web page lets say Reddit dot com slash slash Ah wench's cute photos or
cute images of dogs and cats usually with the occasional reptile lover slash weirdo.
No offense to anyone who has reptiles.
I just can't can't get behind that.
So when I request this hit enter and I'm seeing the human version the interface for me and for all of
us.
But there's also an interface for code to interact with.
There's a web API where we request it and rather than seeing this our computer sees this.
So I'll talk about what this is something called Jaison and just one video from now.
But it's basically another format of data that is better and easier for computers to use.
It doesn't have any of the fluff that we have here because if I'm writing an app let's say want to pit
dogs versus cats and I want to count the number of posts every day that mentioned dogs.
The number of posts every day that mentioned cats and have a chart so you can visit my web site and
there's a live chart that's updating what I would need to do is get that from Reddit.
I would need to ask Reddit you know give me the data today or every hour that update it give me the
current front page of our site.
Ah.
And then I would go through the data.
This data here and calculate you know search for dog search for cat and tally it up and update my graph
every hour.
So that's a simple example.
You can do much more complex things of course.
So here are some other examples of API is Twitter.
You can do things like give me all the tweets that mention ice cream or you know unlike CNN they are
always like live tweets coming in that mentions certain hashtags or certain news events.
Facebook as we talked about so many things you can get from Facebook's API profile pictures likes and
you probably see it all the time in applications where you see that kind of warning or question that
pops up from Facebook it's like this application wants to use your data.
Do you accept it or not or do you.
Permitted or not.
And you can kind of change things.
Who can see what and what data it can access whether API.
So there's lots of weather API is out there that do different things.
Reddit API can we just saw very briefly Google Places what gas stations are near someone.
Google Maps of course to get a map going.
The Yelp API can do things like give me 10 restaurants in the zip code nine for one one.
Lots and lots things you can do.
And then of course by combining them together you can do even cooler things which is actually this site
I teach dot com if this then that is a way to connect API.
So there are 309 services.
And basically this is kind of confusing I guess but it's a way to have a visual interface to connect
API to do things for you.
So I picked up photography on the side and there's so many photography sites if you want to do the whole
social media thing and there's flicker and Instagram Facebook 500 pixels Dropbox and I want and iCloud
and let's say I want all of those and any time I post a photo to Instagram I want it to post to all
of those other places.
You can do that using if this then that.
So these are all the services that they allow.
They worked with so Facebook's API Twitter's API get hubs.
There are some I think there is something called the Internet of Things.
So API is that will exist for physical objects like a thermostat where you can control the temperature
through an API or a video camera security camera where you can use code to turn it on and off or rotate
it or a light bulb that you can change the hue the color of dynamically using code.
So you know in college I had friends who would take light bulbs that were smart electronic ones connected
to the Internet plug them into their dorm and then it would automatically take whatever music was playing
.
They wrote some code that would then kind of turn the lights on and off and change the color to make
a little visualizer for the music.
So there's tons of things on here.
This is just a side thing that's cool for you to check out.
If this than that if you're not familiar with it you can look at browse recipes.
So these are some of the popular things people will do like.
Remind yourself to put on sunscreen when the heat index is high so it will automatically connect to
an API that figures out what the U.V. index is and then it will write some code.
You know whatever.
I don't know what the Ubi index how that works what the scale is but whenever it reaches a certain number
then it will send you an alert receive notification to turn off I find save battery power when you leave
a specific location so you can do all sorts things connect.
You know if this can do that.
All right.
So that all relies on API.
And they support 300 plus AP guys but there are way more API is out there and a great place to see that
is a tool or a site called programmable web and it's a API directory is how they build themselves.
They have 15000 API.
There are more out there.
This is a great place to start.
So if I know I want to use transportation data lets say I want to make an app that will tell you when
the next train is in San Francisco using your current location or will tell you with the latest train
you can take to still make it to work before your first meeting is something like that I would need
an API to figure out when the trains are so I could cook click on transportation here I could do a search
and there's all these different API cers at Yahoo traffic there's a bus Lufthansa for airlines or Indian
Railways.
So this is kind of all over the place you could narrow it down of course.
Or you could look for weather if needed weather data and there's all these API eyes you can click on
one like let's go.
That was interesting climbing weather provides weather data for climbing sites and then I can see you
Oreille for their home page.
Sometimes for sample code.
Not always.
In this case there isn't.
I can see the sites they support the climbing sites and then I can also see an endpoint that will show
you.
Basically this is the site where you can go learn about how the API works.
So we're going to see this in just a moment with the API as we incorporate but this will tell you the
documentation what the data looks like that you'll get back where you're supposed to make a request
to to find certain data.
So that's all I want to show though.
Mainly programmable Web site directory for lots of API is some amazing things on here.
Some sort of obscure things API is to detect nudity and images and then more common things like you
know restaurants and bars and location guides National Park data linked in data maps Facebook you know
lots and lots of things on here.
So great resource.
Also fun just to browse some things they have on here.
If you ever you know a lot of times I would give students a project.
And some people would know immediately they want to use a certain API and then some people weren't inspired
and they needed help.
They wanted inspiration and they just go browse until they find an API that excites them.
Often on programs what Web.
OK.
So one last thing here that I just think is cool is that Tesla Tesla cars and motor cars the electric
car maker has an API.
I think it's unofficial that they don't support it because essentially But there's an API that you can
use to interact with their cars so you can view the documentation here of things you can do.
You can query a car for how charged it is what percentage of the battery is charged how much.
Estimated range.
And this is what you get back.
So when you make a request to this you are l and you have to put in your vehicle ID and I don't have
a test I won't do that.
But if you did you could put it in there and plug it in the red and it would give you this information
.
But you can also do things like ask for the current climate settings temperature inside temperature
outside and then you can do really fun things like wake the car up or open the charging port on the
side.
Start the charging stop charging flash the lights honk the horn so you can write code that will and
there's videos of people who do this they'll have when their alarm goes off in the morning.
Code will automatically check the weather outside and then appropriately set the Tesla.
Well turn the Tesla on first set it to temperature inside to an appropriate temperature depending on
how hot or cold just outside then it will honk the horn and start some music that will you know wakeup
music or something.
And there's videos of this online and you can do that because of the API.
So that's an example of you know the Internet of Things where there is a physical object a thing that
is being controlled through an API.
OK.
So we covered a lot there.
Some of API application programming interface ways for you to write code that interacts with other code
other pieces of data.
Application services typically web API is what most people refer to which our API set are structured
in a way that you interact with them through the web usually through HTP requests.