Flickr API and image arrays
in
Integration and Hardware
•
2 years ago
Please can you help me determine why this code keeps giving me null errors? It displays all the images one by one but then it errors once it reaches the end of the array. Why doesn't it continue to loop?
int maxImages = 24;
int imageIndex = 0;
PImage[] images = new PImage[maxImages];
String api = "http://api.flickr.com/services/rest/?method=flickr.tags.getClusterPhotos&";
void setup() {
size(500, 500);
//text - Free text search. Searches the title, description or tags that contain this text.
//page - Which page of results you want returned
//per_page - Number of photos to return per page
//api_key - Required to access API
String query = api + "tag=monkey&cluster_id=1&format=rest&extras=url_o&api_key=bd7435660785b923332b224789d33c93";
println("Our final query URL:" + query);
println("**********************");
XMLElement xml = new XMLElement(this, query);
println(xml);
XMLElement[] photoTag = xml.getChildren("photos/photo");
for (int i = 0; i < photoTag.length; i++) {
//println(displayPhoto);
String farm = photoTag[i].getString("farm");
String server = photoTag[i].getString("server");
String id = photoTag[i].getString("id");
String secret = photoTag[i].getString("secret");
String img = "http://farm"+farm+".static.flickr.com/"+server+"/"+id+"_"+secret+".jpg";
println(images);
images[i] = loadImage( img );
}
}
void draw() {
background(0);
image(images[imageIndex], 0, 0);
imageIndex = (imageIndex + 1) % images.length;
frameRate(1);
}
int maxImages = 24;
int imageIndex = 0;
PImage[] images = new PImage[maxImages];
String api = "http://api.flickr.com/services/rest/?method=flickr.tags.getClusterPhotos&";
void setup() {
size(500, 500);
//text - Free text search. Searches the title, description or tags that contain this text.
//page - Which page of results you want returned
//per_page - Number of photos to return per page
//api_key - Required to access API
String query = api + "tag=monkey&cluster_id=1&format=rest&extras=url_o&api_key=bd7435660785b923332b224789d33c93";
println("Our final query URL:" + query);
println("**********************");
XMLElement xml = new XMLElement(this, query);
println(xml);
XMLElement[] photoTag = xml.getChildren("photos/photo");
for (int i = 0; i < photoTag.length; i++) {
//println(displayPhoto);
String farm = photoTag[i].getString("farm");
String server = photoTag[i].getString("server");
String id = photoTag[i].getString("id");
String secret = photoTag[i].getString("secret");
String img = "http://farm"+farm+".static.flickr.com/"+server+"/"+id+"_"+secret+".jpg";
println(images);
images[i] = loadImage( img );
}
}
void draw() {
background(0);
image(images[imageIndex], 0, 0);
imageIndex = (imageIndex + 1) % images.length;
frameRate(1);
}
1