I am trying to get a specified set from Flickr and then display the images in that set using the JSON and REST API. Here is the code I am using:
$.getJSON("http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=xxx&set=72157623858739780&format=json&jsoncallback=?", function(data){
$.each(data.items, function(i,item){
$("<img/>").attr("src", item.media.m).appendTo("#images");
});
});
I removed the api key from the example. The url with my key in it, when typed into my web browser, returns the following error:
jsonFlickrApi({"stat":"fail", "code":1, "message":"Photoset not found"})
I know the set id is correct, as navigating to http://www.flickr.com/photos/23892838@N07/sets/72157623858739780/ works fine.
UPDATE
I managed to get things working. Here is my revised code in case others are trying to figure it out.
function FlickrPhotoSet(){
//SET API CALL BASED ON INPUT
var apiCall = "http://api.flickr.com/services/rest/?format=json&method=flickr.photosets.getPhotos&photoset_id=THESET&per_page=10&page=1&api_key=XXX&jsoncallback=?";
//PRINT API CALL (DEBUG)
$("<span>").html(apiCall+"<br>").appendTo("body");
//SEND API CALL AND RETURN RESULTS TO A FUNCTION
$.getJSON(apiCall, function(data){
//LOOP THROUGH DATA
$.each(data.photoset.photo, function(i,photo){
//LINK TO IMAGE SOURCE
var img_src = "http://farm" + photo.farm + ".static.flickr.com/" + photo.server + "/" + photo.id + "_" + photo.secret + "_" + "s.jpg";
//LINK TO IMAGE PAGE (REQUIRED BY FLICKR TOS)
var a_href = "http://www.flickr.com/photos/" + data.photoset.owner + "/" + photo.id + "/";
//PLACE IMAGE IN IMAGE TAG AND APPEND TO IMAGES DIV
$("<img/>").attr("src", img_src).appendTo("#image_block")
//WRAP IN LINK
.wrap(("<a href='" + a_href + "'></a>"))
});
});
};