-
-
Save andrewhaskin/1445424 to your computer and use it in GitHub Desktop.
import com.francisli.processing.http.*; | |
PFont InstagramFont; | |
PImage backgroundimg; | |
PImage userphoto; | |
PImage profilepicture; | |
String username; | |
String tag; | |
String[] tagStrings; | |
HttpClient client; | |
void setup() { | |
size(600, 900); | |
smooth(); | |
backgroundimg = loadImage("globalgram_background.jpg"); | |
InstagramFont = loadFont("Helvetica-Bold-36.vlw"); | |
client = new HttpClient(this, "api.instagram.com"); | |
client.useSSL = true; | |
//// instantiate a new HashMap | |
HashMap params = new HashMap(); | |
//// put key/value pairs that you want to send in the request | |
params.put("access_token", "YOUR ACCESS TOKEN HERE"); | |
params.put("count", "1"); | |
client.GET("/v1/tags/nature/media/recent.json", params); | |
} | |
void responseReceived(HttpRequest request, HttpResponse response) { | |
println(response.getContentAsString()); | |
//// we get the server response as a JSON object | |
JSONObject content = response.getContentAsJSONObject(); | |
//// get the "data" value, which is an array | |
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 | |
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()); | |
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(); | |
} | |
void draw() { | |
background(255); | |
imageMode(CENTER); | |
image(backgroundimg, width/2, height/2); | |
//rectMode(CENTER); | |
//noStroke(); | |
//rect(70, 70, 90, 90); | |
//fill(150); | |
if (profilepicture != null) { | |
image(profilepicture, 70, 70, 90, 90); | |
} | |
imageMode(CENTER); | |
if (userphoto != null) { | |
image(userphoto, width/2, height/2-40, 550, 550); | |
} | |
textFont(InstagramFont, 36); | |
if (username != null) { | |
text(username, 125, 90); | |
fill(150); | |
} | |
textFont(InstagramFont, 14); | |
if ((tagStrings != null) && (tagStrings.length > 0)) { | |
String line = tagStrings[0]; | |
for (int i = 1; i < tagStrings.length; i++) { | |
line += ", " + tagStrings[i]; | |
} | |
text(line, 25, 690, 550, 50); | |
fill(0); | |
} | |
} |
Paolo, this may help you :
http://instagram.com/developer/authentication/
Receiving an access_token
" In order to receive an access_token, you must do the following:
Direct the user to our authorization url.
If the user is not logged in, they will be asked to log in.
The user will be asked if they’d like to give your application access to his/her Instagram data.
The server will redirect the user in one of two ways that you choose:
Server-side flow (reccommended):Redirect the user to a URI of your choice. Take the provided code parameter and exchange it for an access_token by POSTing the code to our access_token url.
Implicit flow: Instead of handling a code, we include the access_token as a fragment (#) in the URL. This method allows applications without any server component to receive an access_token with ease."
Hi, my name is Paolo and I have some problem with your code. First of all there aren't images and fonts but the major issue is respect the ACCESS TOKEN. I don't understand witch is the procedure to obtain it. I try to follow the guideline explained in Developer documentation but without success. Can you help me?
Thank you very much in advance :)