2011-05-18 29 views
1

我想包括飼料的tumblr網頁上的大致如下如何在Tumblr的讀取API中查詢多個標籤?

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

現在,這工作得很好:我得到的所有條目與標籤「有趣的標籤」。

我的問題是:我如何要求多個標籤?如此更改查詢字符串

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

僅返回具有'tag3'的條目。

是否有一些技巧將'AND'或'OR'標籤名稱放在一起?如果沒有,我很樂意查詢所有這些並手動過濾它們,但我認爲這值得提問。

在此先感謝人!

回答

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

好的,有趣的。謝謝! – HumanCatfood 2011-05-18 10:59:38

+0

沒問題。如果這對你有用,如果你能接受答案會很棒(點擊答案旁邊的勾號)。需要任何東西讓我知道:) – 2011-05-18 11:56:45

+0

好的,再次感謝 – HumanCatfood 2011-05-18 14:17:16

0

來自Tumblr API文檔:tagged - Return posts with this tag in reverse-chronological order (newest first).這個標籤是自我解釋,我認爲。

所以,你必須做出幾個請求,對不起

相關問題