We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I am working on a project using Instagram API and found the code below from http://forum.processing.org/two/discussion/9601/instagram-api-integration-with-http-library posted by jayjaylu. I have a problem getting response from responseReceived() function below. getGram() is working, but responseReceived() isn't.. Anyone knows why? Please let me know. Thank you in advance.
import com.francisli.processing.http.*; PImage userphoto; PImage profilepicture; String username; String tag; String[] tagStrings; String comment; com.francisli.processing.http.HttpClient client; void setup() { size(900, 800); smooth(); client = new com.francisli.processing.http.HttpClient(this, "api.instagram.com"); client.useSSL = true; } void getGrams() { //// instantiate a new HashMap HashMap params = new HashMap(); //// put key/value pairs that you want to send in the request params.put("access_token", "1722917717.cbb3637.c9d399ea75b24dad9afe5f8b52e186db"); params.put("count", "1"); client.GET("/v1/tags/cats/media/recent.json", params); } void responseReceived(com.francisli.processing.http.HttpRequest request, com.francisli.processing.http.HttpResponse response) { println(response.getContentAsString()); println("RESPONSE RECEIVED"); //// we get the server response as a JSON object com.francisli.processing.http.JSONObject content = response.getContentAsJSONObject(); //// get the "data" value, which is an array com.francisli.processing.http.JSONObject data = content.get("data"); //// get the first element in the array com.francisli.processing.http.JSONObject first = data.get(0); //// the "user" value is another dictionary, from which we can get the "full_name" string value println(first.get("user").get("full_name").stringValue()); //// the "caption" value is another dictionary, from which we can get the "text" string value //println(first.get("caption").get("text").stringValue()); //// get profile picture println(first.get("user").get("profile_picture").stringValue()); //// the "images" value is another dictionary, from which we can get different image URL data println(first.get("images").get("standard_resolution").get("url").stringValue()); com.francisli.processing.http.JSONObject tags = first.get("tags"); tagStrings = new String[tags.size()]; for (int i = 0; i < tags.size(); i++) { tagStrings[i] = tags.get(i).stringValue(); } comment = first.get("caption").get("text").stringValue(); username = first.get("user").get("full_name").stringValue(); String profilepicture_url = first.get("user").get("profile_picture").stringValue(); profilepicture = loadImage(profilepicture_url, "png"); String userphoto_url = first.get("images").get("standard_resolution").get("url").stringValue(); userphoto = loadImage(userphoto_url, "png"); } void draw() { background(255); imageMode(CENTER); if(frameCount % 100 == 0){ println(frameCount); getGrams(); } if (profilepicture != null) { image(profilepicture, 60, 70, 90, 90); } imageMode(CENTER); if (userphoto != null) { image(userphoto, width/2, height/2.25, 550, 550); } textSize(20); if (username != null) { text(username, 110, 115); fill(0); } else if (username == null) { text("null username", 110, 115); fill(0); } textSize(20); if (comment != null) { text(comment, 15, 700, 550, 100); fill(0); } }
Answers
You'll get a better response if you format your code. Here's how:
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text
Hello bilmore, Thanks for your comment! I just revised it.