我按照本教程创建了一个自定义twitter小部件。它基本上使用Twitter API, Json来提取推文。
http://www.evoluted.net/thinktank/web-development/creating-your-own-twitter-trends-widget在教程中,我得到了tweet。但我想限制推文的数量,可能出现2。
Site - http://testingweddev.comli.com/
为url添加rpp=
参数
$(document).ready(function() {
// json call to twitter to request tweets containing our keyword, in this case 'sheffield'
$.getJSON("http://search.twitter.com/search.json?q=sheffield&rpp=2&callback=?", function(data) {
// loop around the result
$.each(data.results, function() {
var text = this.text;
if(text.charAt(0) != '@') {
// construct tweet and add append to our #tweets div
var tweet = $("<div></div>").addClass('tweet').html(text);
// analyse our tweet text and turn urls into working links, hash tags into search links, and @replies into profile links.
tweet.html('<div class="content">' +
tweet.html()
.replace(/((ftp|http|https)://(w+:{0,1}w*@)?(S+)(:[0-9]+)?(/|/([w#!:.?+=&%@!-/]))?)/gi,'<a href="$1">$1</a>')
.replace(/(^|s)#(w+)/g,'$1<a href="http://search.twitter.com/search?q=%23$2">#$2</a>')
.replace(/(^|s)@(w+)/g,'$1<a href="http://twitter.com/$2">@$2</a>')
+ '<br /><a href="http://www.twitter.com/' + this.from_user + '/status/' + this.id_str + '" class="view" target="_blank">' + $.timeSinceTweet(this.created_at) + '</a></div>'
)
.prepend('<a href="http://www.twitter.com/' + this.from_user + '" target="_blank"><img src="' + this.profile_image_url + '" width="48" height="48" /></a>')
.appendTo('#tweets')
.fadeIn();
}
});
});
});
不要忘记切换到API 1.1。请参阅API 1.1搜索文档。API 1.1使用count参数来指定tweets限制