We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm having problems with using JSON to grab images from instagram in Javascript mode.
JSONObject jsonAgram;
PImage displayInstaImage1;
String apiKey = "xxxxxxxxxxxxx"; //needs valid Instagram API key
String tagSearch;
void setup() {
println("setup");
size(320,320);
tagSearch = "pizza";
loadData();
}
void draw() {
println("draw");
image(displayInstaImage1,0,0);
}
void loadData() {
println("loadData1");
//doesn't seem to make it past the this point
jsonAgram = loadJSONObject("https://api.instagram.com/v1/tags/"+tagSearch+"/media/recent?client_id="+ apiKey);
println("loadData2");
JSONArray instagramData = jsonAgram.getJSONArray("data");
JSONObject entry1 = instagramData.getJSONObject(0);
JSONObject image1Data = entry1.getJSONObject("images").getJSONObject("low_resolution");
String image1URL = image1Data.getString("url");
displayInstaImage1 = loadImage(image1URL);
}
Same old song and dance: works fine in Java mode, but not Javascript. When I run it in JS, it shows up as a gray screen. Using println commands to debug, it looks like things move along until I use "loadJSONObject".
Does the JSON functionality work with JS mode? I know certain libraries won't, but since JSON was integrated into Processing native libraries I thought it should work.
Or could it be something else I'm missing? It would be nice to have a clearer understanding of what will and won't work in Javascript mode.
Answers
For some reason the code formatting is being weird with the URL listed for loadJSONObject. It is formatted properly, as follows:
jsonAgram = loadJSONObject("https://api.instagram.com/v1/tags/"+tagSearch+"/media/recent?client_id="+ apiKey)
To avoid this forum posting bug, split apart "http://" from the rest of the URL link: ;)
jsonAgram = loadJSONObject("https://" + "api.instagram.com/v1/tags/" + tagSearch + "/media/recent?client_id=" + apiKey);
Processing 2+ launched w/ many new data-structures! Unfortunately, JS is still @ v1.4.1! :o3
http://processingjs.org/download/
http://processingjs.org/reference/
This guide has some options on how to mix Java + JS up: %%-
http://processingjs.org/articles/PomaxGuide.html
Thanks so much! I wish it could be a little simpler, but its exactly what I needed to know.
You might need to use JsonP to load data from other sites, because of JS restrictions for security reasons.