gpt4 book ai didi

javascript - 如何在 Flickr API 中按相关性排序?

转载 作者:行者123 更新时间:2023-11-28 07:54:01 25 4
gpt4 key购买 nike

我有以下使用 flickr API 的函数,但是我希望能够按相关性对图像顺序进行排序。我可以在哪里指定这个?是在这个函数中还是在第一个将可用图像(查询多个 api 的搜索词)存储在数组中的函数中。

function printFlickrImages(){
$("#output").append("<h3>Flickr</h3><p>"
+availableImages["flickr"]["numImages"]+" images found from <a href='http://"
+availableImages["flickr"]["url_pattern"]+"'>"
+availableImages["flickr"]["url_pattern"]+"</a></p>");

for (var i in availableImages["flickr"]["images"]){
var url_comps = availableImages["flickr"]["images"][i].split("/");
var photo_id = url_comps[url_comps.length-2];

$.getJSON(flickr_url+photo_id, function(data) {
console.log(data);
if(data.stat == "ok" && data.photo.usage.candownload == 1){
var flickr_image_url = "http://farm"+data.photo.farm
+".staticflickr.com/"+data.photo.server
+"/"+data.photo.id+"_"+data.photo.secret+"_z.jpg";
console.log(flickr_image_url);
$("#output").append("<img src='"+flickr_image_url+"'>");
}else{
console.log("Image protected.");
}
});
}
}//close printFlickr Images

最佳答案

如果您使用flickrapi module :

var Flickr = require("flickrapi"),
flickrOptions = {
api_key: "your key",
secret: "your secret",
user_id:"your userid"
access_token: "your access token",
access_token_secret: "your token secret"
};

Flickr.authenticate(flickrOptions, function(error, flickr) {
// we can now use "flickr" as our API object
flickr.photos.search({ // this is searching for photos
text: "whatever search you want to do",
safe_search: 1,
content_type: 1,
sort: "relevance", // this is where you sort by relevance
// you can also sort by date-posted-asc, date-posted-desc, date-taken-asc, date-taken-desc, interestingness-desc, interestingness-asc
page: 1,
per_page: 10
}, function(err, result) {
console.log(result.photos.photo) // this displays the ten photos returned by this search
console.log(result.photos.photo[0]) // this displays the first of your ten photos
});
});

请注意我在哪里使用sort:“relevance”。您还可以按 date-posted-asc、date-posted-desc、date-taken-asc、date-taken-desc、interestness-desc、interestness-asc 排序

关于javascript - 如何在 Flickr API 中按相关性排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26359510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com