For this homework assignment, I used the NYTimes API in attempting to create simple data visualization with movie reviews. I wasn’t able to get far in my sketch because I was struggling with attaching the Key to the API JSON string.
Tried the following that didn’t work:
1) var url = ‘https://api.nytimes.com/svc/movies/v2/reviews/search.json’+’&APPID=ADD KEY HERE‘;
2) var url = ‘https://api.nytimes.com/svc/movies/v2/reviews/search.json’
var apikey = ‘?&apikey=ADD KEY HERE‘;
But this line worked:
loadJSON(“https://api.nytimes.com/svc/movies/v2/reviews/search.json?api-key=ADD KEY HERE“, gotData);
Now that I was finally able to attach the data to the sketch, it now displays 1 ‘film title’ of the movie review in the console. I tried following Shiffman’s NYTimes & API video to create variables (eg: createElements and createP) but the results doesn’t run, so I’m stuck at that point for now.
function setup() {
createCanvas(200,200);
loadJSON("https://api.nytimes.com/svc/movies/v2/reviews/search.json?api-key=ADD KEY HERE", gotData);
}
function gotData(data) {
//var articles = data.results;
//for (var i = 0; i < articles.length; i++) {
//createP(articles[i].display_title);
/*background(0);
for (var i = 0; i < data.number; i++) {
fill(255);
ellipse(random(width), random(height), 16, 16);*/
//println(data);
println(data.results[0].display_title);
}