我正在尝试大致如下在网页上包含 Tumblr 提要
$.ajax({
url: 'http://mypage.tumblr.com/api/read/json?tagged=interesting+tag',
type: 'GET',
dataType: 'jsonp',
success: renderStuff,
error: function () {
alert('D\'oh'!)
}
});
现在,这一切正常:我得到了所有带有“interesting tag”标签的条目。
我的问题是:如何请求多个标签?像这样更改查询字符串
'http://mypage.tumblr.com/api/read/json?tagged=tag1&tagged=tag2&tagged=tag3'
仅返回带有“tag3”的条目。
是否有一些技巧可以将“AND”或“OR”标签名称组合在一起?如果没有,我很乐意查询所有这些并手动过滤它们,但我认为这值得一问。
在此先感谢大家!!
最佳答案
目前的 Tumblr API 不可能,它只支持一个标签。一种解决方法是(除了从 Tumblr 团队插入此功能外)使用 jQuery 延迟对象来获取所有带有这些标签的帖子并合并 json 结果。
function getPostsByTag(tag) {
return $.ajax({
url: 'http://mypage.tumblr.com/api/read/json?tagged=' + tag,
type: 'GET',
dataType: 'jsonp'
});
};
$.when(getPostsByTag('tag1'), getPostsByTag('tag2'), getPostsByTag('tag3'))
.then(function() {
var posts = $.extend({}, arguments);
renderStuff(posts);
});
关于javascript - 如何在 Tumblr 的阅读 api 中查询多个标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6043119/