2011年04月Archive for

如何使用Flickr的API

首先要去申请Flickr API Key, 分为商业通途和非商业用途。

Flickr API Key Application Application

通常大家会get方式获得图片列表,如访问下述地址会获得json格式的图片列表

http://api.flickr.com/services/rest/?&method=flickr.people.getPublicPhotos
&api_key=[your api key here]&photoset_id=[your photoset id here]&format=json&per_page=20
$(function(){
       $.getJSON('http://api.flickr.com/services/rest/?&method=flickr.photosets.getPhotos&api_key=[your api key here]&photoset_id=[your photoset id here]&format=json&per_page=20&jsoncallback=?',
        function(data){
            //loop through the results with the following function
            $.each(data.photoset.photo, function(i,item){
            	var str = "";
                //build the url of the photo in order to link to it
                var photoURL = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_m.jpg';
                var href = 'http://www.flickr.com/photos/' + data.photoset.owner + '/' + item.id;
                str += '