2013-06-12 1 views
1

파일 이름에 따라 Flickr에서 특정 이미지를 표시하는 방법. 이미지를 검색하고 검색 결과에 맞는 이미지 만 표시하고 싶습니다.검색 결과에 따라 Flickr 이미지 얻기

솔직히 말해서 내가 처음으로 Flickr를 사용하고 있으며 실제로 몇 가지 예제를 추가해야합니다.

어디서부터 시작해야할까요?

+1

확인하셨습니까? http://mashupguide.net/1.0/html/ch08s07.xhtml – Chris

+0

@Chris 고맙습니다. Chris 한 번 보겠습니다. 다른 사람은 당신이 –

답변

1

다음은 내가 함께 던진 도우미 메서드로, flickr의 api에 요청할 수 있습니다. flickr api documentation을 들여다 보면 도움이 될 것입니다. 그러면 돌아 오는 데이터를 처리하는 방법을 알아낼 수 있습니다. 이것은 크롬과 파이어 폭스에서 작동해야하며 IE 나 Safari에서 테스트하지 않았습니다.

/* 
* Make an XmlHttpRequest to api.flickr.com/services/rest/ with query parameters specified 
* in the options hash. Calls cb once the request completes with the results passed in. 
*/ 

var makeFlickrRequest = function(options, cb) { 
    var url, xhr, item, first; 

    url = "http://api.flickr.com/services/rest/"; 
    first = true; 

    for (item in options) { 
    if (options.hasOwnProperty(item)) { 
     url += (first ? "?" : "&") + item + "=" + options[item]; 
     first = false; 
    } 
    } 

    xhr = new XMLHttpRequest(); 
    xhr.onload = function() { cb(this.response); }; 
    xhr.open('get', url, true); 
    xhr.send(); 

}; 

사용법 :

var makeFlickrRequest = function(options, cb) { 
    var url, item, first; 

    url = "http://api.flickr.com/services/rest/"; 
    first = true; 
    $.each(options, function(key, value) { 
    url += (first ? "?" : "&") + key + "=" + value; 
    first = false; 
    }); 

    $.get(url, function(data) { cb(data); }); 

}; 

이 방법은 비의 jQuery 버전과 같은 사용이 있습니다

var options = { 
    "api_key": "<your api key here>", 
    "method": "flickr.photos.search", // You can replace this with whatever method, 
            // flickr.photos.search fits your use case best, though. 
    "format": "json", 
    "nojsoncallback": "1", 
    "text": "<your search text here>" // This is where you'll put your "file name" 
} 

makeFlickrRequest(options, function(data) { alert(data) }); // Leaving the actual 
                  // implementation up to you! ;) 

당신이 jQuery를 사용하는 경우, 여기에 jQuery를 버전입니다.

+0

좋은 해결책을 안다면 몇 가지 예제를 게시 할 자유롭게 ... 나는이 코드가 나를 위해 어떻게 작동하는지 보려고 노력할 것입니다. 너에게 다시 돌아갈 게 –