Jquery JSON Flickr API Returning Photos in a Set
Asked Answered
D

1

12

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>"))
      });

    });


};
Decadence answered 8/12, 2010 at 1:58 Comment(2)
what is the issue above?? you mean the flicker is not returning data??Nevels
type the url directly on browser , if it gives the same error data, that means your url data is wrong, there is no issue in javascript thereNevels
E
2

From the flickr API docs it looks like your set parameter in your URL should be photoset_id.

Essen answered 8/12, 2010 at 2:3 Comment(1)
Thanks! I decided to go the pure javascript route and got it to work.Decadence

© 2022 - 2024 — McMap. All rights reserved.