如何在Tumblr的read api中查询多个标签?

Hum*_*ood 1 javascript ajax tumblr

我试图在网页上大致包含Tumblr提要,如下所示

    $.ajax({
        url: 'http://mypage.tumblr.com/api/read/json?tagged=interesting+tag',
        type: 'GET',
        dataType: 'jsonp',
        success: renderStuff,
        error: function () {
            alert('D\'oh'!)
        }
    });
Run Code Online (Sandbox Code Playgroud)

现在,这很好用:我得到所有带有"有趣标签"标签的条目.

我的问题是:我如何要求多个标签?像这样更改查询字符串

'http://mypage.tumblr.com/api/read/json?tagged=tag1&tagged=tag2&tagged=tag3'
Run Code Online (Sandbox Code Playgroud)

仅返回带有'tag3'的条目.

"AND"或"OR"标签名称是否存在一些技巧?如果没有,我很乐意只查询所有这些并手动过滤它们,但我认为值得一提.

在此先感谢人们!!

Gar*_*een 7

目前的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);
 });
Run Code Online (Sandbox Code Playgroud)