This video demonstrates how to work with an API. The example uses open weather map. How do you form an API query? How do you get an API key? How do you use the JSON data the API sends you back? Oh, and what is an API?
All examples: https://github.com/shiffman/Video-Lesson-Materials
Contact: https://twitter.com/shiffman
Next video:
JavaScript basics:
HTML/CSS basics:
Full Data playlist:
Help us caption & translate this video!
http://amara.org/v/QbuE/
Original source
47 responses to “8.5: Working with APIs in Javascript – p5.js Tutorial”
If you were to move your code in setup() would you still need if(weather)?
Can you change the response of API? Does it work on PHP? Please help…
The real content starts at 12:10
nice tutorial… really cought my attention and learn something to be a beginner..thanks
You're awesome
You're awesome dood thanks for all your great videos! Love your style yo!
very nice
finally a video with info i can use. WELL DONE!
Thank you
Do you ever do talks? I need to witness you in person sharing your knowledge! Incredible teacher.
Just wanted to let you know, you have the best stuff I have seen to explain APIs. I did not begin to comprehend the concepts until I started watching your videos. Thanks for putting this out there.
Hi Daniel, PLEASE PLEASE help us with the Instagram API. Teach us how to use it, there are no YouTube tutorials at all …..THANK YOU!!!!
How can you loadJSON when you don't have p5, what do I have to install?
Thank you, very helpful video.
Why would anyone include "I'm looking for" in their searches?
This was the best explanation I ever seen for Api's.
Better Example would be getting random wallpapers like I did in a project there a reaaally big free open API without need for keys, just google random wallpaper api 😀 Just saying, because there you wouldnt have to log in to request data..
Very helpful. Thanks!
Daniel, great videos! Thank you so much!
Daniel, I have GeoJson file from which I need to eliminate the initial tags {"type"=FeatureCollection"… Basically I would like to extract the "features" attribute and turn it into a CSV. Any suggestions? Tutorials? Thanks in advance!
Great API-usage tutorial!
11:00 Ctrl-F "temperature"!
Excellent Tutorial.Thank You!
i love this guy!!! I love you!!!!!!!! Thank you thank you thank you!!!!!
you are awesome sir… absolutely awesome, please made tutorial for Javascript…. like from scratch without p5 please please please,,, then jquery then angular .. be my Library sir.. if there is anything where i have to pay please let me for your paid channel because you are awesome…
Hi Dan thank you so much for making these coding tutorials so creatively and entertaining!!! I have not yet managed to fall asleep..haha. I have a question on how to catch errors when there's some sort of failure using loadJSON. Similar to what $.ajax has like this:
$.ajax({
url: "lines.txt", // path to file
dataType: 'text', // type of file (text, json, xml, etc)
success: function(data) { // callback for successful completion
$("#sentences").html(data);
},
error: function() { // callback if there's an error
alert("error");
}
});
});
Awesome video and really helpful!! Thanks
Nice video,! it has great learning material and the visual effect of you being inside the screen plus your step by step guidance and your going-openly-through-the-process makes it feel familiar and interesting.Thanks!!
I'd hug you if I could, Dan. Thanks for the series so far!
You have no idea how helpful these videos are. Thank you very very very much.
Perfect teaching style and the best tutorial about API.
Your new subscriber 🙂
Awesome tutorial.
i am trying to load json data on codepen but it doesn't work, any tips.
$.getJSON(api_test_v2, getdata, 'jsonp'); i tried with jsonp and without nothing changed
im working with an API that returns an image, how do i display it?
Hi Daniel, I am going nuts cause I am trying to use this with Node.Js and it's telling me that the loadJSON(); function doesn't exist… is loadJSON a native Js function or is it something that you coded to get the JSON data from the server or a library or something? …I'm honestly starting to feel dumb xd HEEEEEEEEEELP PLEASEEEEE ;w;
Hello Daniel,
How do you do this with geolocation in processing? I've been trying to use navigator.geolocation.getCurrentPosition. But I guess I'm not following the right rules.
this was a hell of a video, everything is much simpler now 😀
if someone tell me ,which code editor he used ?
PLEASE HELP ANYONE!! how do you access an API's response with an integer as its object, example data.results.0;
When I try this, it brings up an error in my console log of (Uncaught SyntaxError: Unexpected number)… please help…
im curious why you use a mac per. to a pc?
class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.hidden = true
self.parseJson()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
var country: String = ""
var capital: String = ""
var latitude: Double = 0.0
var longitude: Double = 0.0
var output:NSArray!
func parseJson(){
if let path = NSBundle.mainBundle().pathForResource("capitals", ofType: "json") {
do {
let jsonData = try NSData(contentsOfFile: path, options: NSDataReadingOptions.DataReadingMappedIfSafe)
do {
let jsonResult: NSDictionary = try NSJSONSerialization.JSONObjectWithData(jsonData, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
for (key,value) in jsonResult
{
if key as! String == "Results"
{
output = value as! NSArray
}
}
// for item in output
// {
//
// capital = item["Capital"] as! String
// latitude = item["Latitude"] as! Double
// longitude = item["Longitude"] as! Double
//
// }
//
dispatch_async(dispatch_get_main_queue()){
self.tableView.hidden = false
self.tableView.reloadData()
}
// print(output)
} catch {}
} catch {}
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
var country:[String] = []
//var capital: [String] = []
for item in output
{
//print(item["Country"]!)
//country.append(item["Country"] as! String)
country.append(item["Capital"] as! String)
}
cell.textLabel?.text = country[indexPath.row]
//cell.detailTextLabel?.text = capital[indexPath.row]
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print(output!.count)
return output!.count
}
}
Hey, loved this video! You said, "Look at me! 10 minutes in…" and I had to check the progress bar because I couldn't believe it had been 10 minutes already! Most other tutorials feel like they take forever but yours are extremely interesting and you're fun to watch! Thanks for the awesome tut because I've been stuck on this for weeks hahahah
This is definitely among my favorite programming channels on YouTube. I love the enthusiasm in your videos. Keep it up!
the explanation of when we are watching this was fantastic !!!great videos !!
2k Followers in your IG Account Rightaway http://storage.googleapis.com/0882103204455/5735467299519.html
what library is loadJSON a part of ?
i love this guy! you keep it so real with your audience. My coding bootcamp was doing soundcloud api today, and i just wanted to cry. thats how i find myself here
I love your videos! But the sidenavigation on https://p5js.org/examples/ is mildly disturbing and the top position calculation is not correct 😀