how can I use multiple HTTP clients in a processing sketch?
in
Contributed Library Questions
•
1 year ago
I have a sketch which uses the http library found here (
http://francisli.github.com/processing-http/ ) to get instagram information on popular instagram photographs. I would also like to be able to get specific information on the uploader of the photograph through another http request.
I can only find examples of single requests and am not sure how I could go about getting more specific information through another http request.
The code is here:
https://github.com/nosarious/instagram_Array
but I am including it here as well. Any help would be appreciated.
- import com.francisli.processing.http.*;
- String clientID = " "; //put your clientID here Get it from instagram site: http://instagram.com/developer/
- int totalCheck = 9;
- int currentItem = 0;
- PImage[] userphoto = new PImage[totalCheck];
- PImage[] profilepicture = new PImage[totalCheck];
- String[] username = new String[totalCheck];
- String[] userID = new String[totalCheck];
- String tag[] = new String[totalCheck];
- String[] tagStrings = new String[totalCheck];
- String[] search = new String[totalCheck];
- int[] comments = new int[totalCheck];
- int[] likes = new int[totalCheck];
- float likedCount[];
- HttpClient client;
- HttpClient Personal;
- void setup() {
- size(800, 800, P2D);
- smooth();
- // create new client
- client = new HttpClient(this, "api.instagram.com");
- // use https
- client.useSSL = true;
- // search for the artist Radiohead
- String mediaLookup = "popular";
- // instantiate a new HashMap
- HashMap params = new HashMap();
- // pass parameters as key-value pairs
- params.put("client_id", clientID);
- for (int i=0;i<totalCheck-1;i++){
- // make the request
- client.GET("v1/media/popular?client_id="+clientID);
- }
- }
- void draw() {
- if (currentItem==totalCheck-1){
- imageMode(CENTER);
- for (int i=0;i<totalCheck;i++){
- imageMode(CENTER);
- if (profilepicture[i] != null) {
- image(profilepicture[i], 82, 90, 90, 90);
- }
- if (userphoto[i] != null) {
- image(userphoto[i], 100*i-50, height/2-30, 100, 100);
- }
- delay(100); // small delay
- }
- }
- }
- void responseReceived(HttpRequest request, HttpResponse response) {
- //// we get the server response as a JSON object
- JSONObject content = response.getContentAsJSONObject();
- // println(content);
- //// get the "data" value, which is an array
- if (content.get("data") != null) {
- currentItem ++;
- JSONObject data = content.get("data");
- //// get the first element in the array
- JSONObject first = data.get(0);
- //// the "user" value is another dictionary, from which we can get the "full_name" string value
- if (first.get("user").get("id").stringValue() != null) {
- println(first.get("user").get("id").stringValue());
- }
- if (first.get("user").get("full_name").stringValue() != null) {
- println(first.get("user").get("full_name").stringValue());
- }
- //// get profile picture
- if (first.get("user").get("profile_picture").stringValue() != null) {
- println(first.get("user").get("profile_picture").stringValue());
- }
- //// the "images" value is another dictionary, from which we can get different image URL data
- if (first.get("images").get("standard_resolution").get("url").stringValue() != null) {
- println(first.get("images").get("standard_resolution").get("url").stringValue());
- }
- if (first.get("likes").get("count").intValue() != 0) {
- println("Likes: "+first.get("likes").get("count").intValue());
- likes[currentItem] = first.get("likes").get("count").intValue();
- }
- if (first.get("comments").get("count").intValue() != 0) {
- println("Comments: "+first.get("comments").get("count").intValue());
- comments[currentItem] = first.get("comments").get("count").intValue();
- }
- if (first.get("user").get("id").stringValue() != null) {
- userID[currentItem] = first.get("user").get("id").stringValue();
- }
- if (first.get("user").get("full_name").stringValue() != null) {
- username[currentItem] = first.get("user").get("full_name").stringValue();
- }
- if (first.get("user").get("profile_picture").stringValue() != null) {
- String profilepicture_url = first.get("user").get("profile_picture").stringValue();
- profilepicture[currentItem] = loadImage(profilepicture_url, "png");
- }
- if (first.get("user").get("profile_picture").stringValue() != null) {
- String userphoto_url = first.get("images").get("standard_resolution").get("url").stringValue();
- userphoto[currentItem] = loadImage(userphoto_url, "png");
- image(userphoto[currentItem],100,100);
- }
- println(currentItem);
- }
- }
1