I have had a few requests here and there for a Processing sketch to access the Instagram API and retrieve photographs.
Here is code for a very simple Processing sketch that retrieves and saves the first 10 photographs of an image based on provided hashtag. In the JSONObject, make sure to swap in your tag and client id.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
void setup() { size(640, 640); JSONObject instagram = loadJSONObject("https://api.instagram.com/v1/tags/YOURTAGHERE/media/recent?client_id=YOURCLIENTIDHERE"); JSONArray photos = instagram.getJSONArray("data"); println(photos); for (int i = 0; i < photos.size(); i++) { String url1 = photos.getJSONObject(i).getJSONObject("images").getJSONObject("standard_resolution").getString("url"); PImage img = loadImage(url1, "jpg"); img.save("output/result"+i+".jpg"); image(img, 0, 0, 640, 640); } } void draw() { noLoop(); } |