如何根据文件名显示Flickr中的某些图像。我想搜索图片,只显示那些适合我的搜索结果。
老实说,这是我第一次使用Flickr,他们真的需要更多的例子。
知道从哪里开始吗?
发布于 2013-06-12 20:37:06
下面是我附带的一个帮助方法,它允许您对flickr的api提出请求。查看一下flickr api文档可能会有帮助,这样您就可以开始弄清楚如何处理您将要返回的数据。这应该适用于Chrome和Firefox,我还没有在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 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版本:
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版本的用法相同。
https://stackoverflow.com/questions/17071187
复制相似问题