开发者

+20 photos flickr api

开发者 https://www.devze.com 2023-03-27 13:28 出处:网络
I am trying to get +20 photos in a flickr feed. On another forum, someone posted the following code as an answer. I inserted my API + setID in the lines 2-3, but it didn\'t work.

I am trying to get +20 photos in a flickr feed. On another forum, someone posted the following code as an answer. I inserted my API + setID in the lines 2-3, but it didn't work.

$(document).ready(function() {  
    var apiKey = ‘******I inserted my API here’;  
    var photoSetID = ‘********set ID’;  
    var jsonURL = 'http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&extras=url_o&photoset_id=' + photoSetID +   
        '&per_page=500&api_key=' + apiKey + '&format=json&jsoncallback;=?';    
    $.getJSON(jsonURL, function(data){  
        $.each(data.photoset.photo, function(i,item){  
            var imgSrc = ‘http://farm’ + item.farm + ‘.static.flickr.com/’ + item.server + ‘/’ +  
            item.id + ‘_’ + item.s开发者_如何学运维ecret + ‘_b.jpg’;  
            $(’ <img >’).attr(’src’, imgSrc).appendTo(’#images’);  
        });  
    });  
});    

I think my two main problems are- where in here do I replace the info with my own:

var jsonURL = 'http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&extras=url_o&photoset_id=' + photoSetID + '&per_page=500&api_key=' + apiKey + '&format=json&jsoncallback;=?';

And what is the purpose of this code?

var imgSrc = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_b.jpg'; 

Thanks so much, my understanding of Jquery is limited and the documentation on flickr api is surprisingly scarce for beginners.

Kelsey


Go to your or the photostream page on flickr and scroll down to the bottom of the page where it says Subscribe to users's photostream. Click the on the orange RSS feed icon then you will find the feed for the photostream. At the top address there will be an id that looks like 49269824@N04 this, put that in the code below and add a div with an id of flickr to your body of you web page.

<html> 
<head> 
<title>Flick Test</title>
<script src="http://code.jquery.com/jquery-latest.js"></script> 

<script>


$(function(){       

    var id='49269824@N04';

    // Flickr Photostream feed link.
    $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=" + id + "&lang=en-us&format=json&jsoncallback=?", 

    function(data){$.each(data.items, 

    function(i,item){

        // Number of thumbnails to show.            
        if(i < 20){

        // Create images and append to div id flickr and wrap link around the image.
        $("<img/>").attr("src", item.media.m.replace('_m', '_s')).appendTo("#flickr").wrap("<a href='" + item.media.m.replace('_m', '_z') + "' name='"+ item.link + "' title='" +  item.title +"'></a>");


        }

    }); 

    }); 

    });

</script> 

</head> 
<body> 
<div id="flickr"></div>
</body> 
</html>

You can set a limit on how many images you want by changing the number in if(i < 20){.... in the above.

Good Luck.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号