Every now and than i get to play cat and mouse with Instagram API. Today I’ve stumbled this recent article Instagram Data Scraping from Public API
I’ve followed the guidelines in processing and stumbled with a few problems.
- using HTTPReuquests I’ve received nothing, or it’s displaying nothing
Code 1 using HTTP Requests
import http.requests.*;
String path="https://www.instagram.com/ligalightbr/?__a=1";
void setup() {
getInstaData();
}
void getInstaData() {
GetRequest get = new GetRequest(path);
get.send();
println("request done");
String s=get.getContent();
println("s: "+s);
}
So in safari (user scraping doesn’t work on firefox, only hastags) I’ve typed the url and copied and pasted the result to a localy built JSON file(Sublime Text). I’ve got success in loading the JSON file and got the data that I want to get, image_URL and picture caption. Now i have another problem, processing is not loading the remote jpg file.
Code 2 - local JSON
JSONObject insta;
String file="brumadinho.json";
void setup() {
size(400, 400);
getInstaData();
}
void getInstaData() {
insta=loadJSONObject(file);
JSONObject graphql=insta.getJSONObject("graphql");
JSONObject user=graphql.getJSONObject("user");
JSONObject media=user.getJSONObject("edge_owner_to_timeline_media");
JSONArray edges=media.getJSONArray("edges");
for (int i=0; i<1; i++) {
JSONObject node=edges.getJSONObject(i);
JSONObject node2=node.getJSONObject("node");
String img_url=node2.getString("display_url");
PImage img=loadImage(img_url);
println(img_url);
}
}
Running Code2 i get the following response
Could not find a method to load https://instagram.fgru5-1.fna.fbcdn.net/vp/7ba46c391120b4ae316dbb721d81552a/5CEEB59C/t51.2885-15/e35/50624103_1248853018572556_70277466767539002_n.jpg?_nc_ht=instagram.fgru5-1.fna.fbcdn.net
https://instagram.fgru5-1.fna.fbcdn.net/vp/7ba46c391120b4ae316dbb721d81552a/5CEEB59C/t51.2885-15/e35/50624103_1248853018572556_70277466767539002_n.jpg?_nc_ht=instagram.fgru5-1.fna.fbcdn.net
Using http requests again i’ve got the raw image data, but could not parse it into an image.
Code 3
void getInstaData() {
insta=loadJSONObject(file);
JSONObject graphql=insta.getJSONObject("graphql");
JSONObject user=graphql.getJSONObject("user");
JSONObject media=user.getJSONObject("edge_owner_to_timeline_media");
JSONArray edges=media.getJSONArray("edges");
for (int i=0; i<1; i++) {
JSONObject node=edges.getJSONObject(i);
JSONObject node2=node.getJSONObject("node");
String img_url=node2.getString("display_url");
GetRequest get = new GetRequest(img_url);
get.send(); // program will wait untill the request is completed
println("response: " + get.getContent());
PImage img=loadImage(get.getContent());
println(img_url);
}
}
Using code 3 got me an obvious error.
Could not find a method to load …
So anyone knows if is there some encryption or other stuff that’s going on? if i copy and paste the img_url in any browser it loads the image as it should do, but processing returns nothing. anyone knows whats going on?
tks in advance