How to query multiple tags in Tumblr's read api?

折月煮酒 提交于 2019-11-29 16:29:21

问题


I'm trying to include Tumblr feeds on a webpage roughly as follows

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

Now, this works fine: I get all entries with the tag 'interesting tag'.

My question is: How do I ask for multiple tags? Changing the query string like this

'http://mypage.tumblr.com/api/read/json?tagged=tag1&tagged=tag2&tagged=tag3'

only returns entries with 'tag3'.

Is there some trick to 'AND' or 'OR' tag-names together? If not, I'd be happy to just query all of them and filter them manually but I thought it would be worth asking.

Thanks in advance people!!


回答1:


Not possible with the current Tumblr API, it only supports one tag. One workaround is to (aside from pushing for this feature from the Tumblr team) is to use jQuery deferred object to get all the posts with those tags and merge the json results.

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);
 });



回答2:


From Tumblr API Docs : tagged - Return posts with this tag in reverse-chronological order (newest first). with this tag is self explanatory, I think.

So, you'll have to make several requests, sorry



来源:https://stackoverflow.com/questions/6043119/how-to-query-multiple-tags-in-tumblrs-read-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!