We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone..
I am trying to load Instagram photos using processing. This is school project and I am not good at programming.. Also I don't know about JSON or Jquery.. but I want to do this.. I need your help!
I found proper library, so I imported it. And below is my code I followed other code. (ref: http://forum.processing.org/two/discussion/6011/instagram-processing-real-time-view#Item_3)
1. I want to know how I can combine Instagram API and below code.
-myClient.GET("/v1/media/popular.json", params);
e.g. If Instagram provide below API,
https://api.instagram.com/v1/media/3?access_token=ACCESS-TOKEN
Can I use that like..
-myClient.GET("/v1/media/3.json", params);
2. I think the responseReceived() was not activated. I see some messages about requesting.. but I couldn't see any messages about responses..
If you wanna try this, you can get user_token from below link. However, you need to get Client ID from Instagram and register Redirect URL to them.
- https://instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token
import com.francisli.processing.http.*;
HttpClient myClient;
String username = USER_NAME;
String usertoken = USER_TOKEN;
PImage userphoto;
void setup(){
size(720,720);
smooth();
myClient = new HttpClient(this, "api.instagram.com");
myClient.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", usertoken);
params.put("count", "0");
myClient.GET("/v1/media/popular.json", params);
}
void responseReceived(HttpRequest request, HttpResponse response) {
println(response.getContentAsString());
//// 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();
}
*/
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");
//noLoop();
//Display Photo();
}
void draw() {
background(255);
display();
}
void mouseClicked() {
//Call Instagram
getGrams();
}
void display() {
if (userphoto != null) {
image(userphoto, width/2, height/2.25, 550, 550);
} else {
println("User photo is NULL");
}
if (username != null) {
text(username, 110, 115);
fill(0);
}
}