Json 自定义Twitter小部件-限制推文数量

Json 自定义Twitter小部件-限制推文数量,json,widget,twitter,Json,Widget,Twitter,我按照本教程创建了一个自定义twitter小部件。 它基本上使用twitterapi、Json来拉推 正如在教程中一样,我收到了推文。 但是我想限制tweet的数量,看起来可能只有2条 站点-向url添加rpp=参数 $(document).ready(function() { // json call to twitter to request tweets containing our keyword, in this case 'sheffield' $.getJSON("htt

我按照本教程创建了一个自定义twitter小部件。 它基本上使用twitterapi、Json来拉推

正如在教程中一样,我收到了推文。 但是我想限制tweet的数量,看起来可能只有2条


站点-

向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();
      }
    });
  });
});
$(文档).ready(函数(){
//json调用twitter请求包含我们关键字的推文,在本例中为“谢菲尔德”
$.getJSON(“http://search.twitter.com/search.json?q=sheffield&rpp=2&callback=?,函数(数据){
//围绕结果循环
$.each(data.results,function(){
var text=this.text;
if(text.charAt(0)!=“@”){
//构造tweet并将append添加到我们的#tweets div
var tweet=$(“”).addClass('tweet').html(文本);
//分析推文文本,将URL转换为工作链接,将哈希标记转换为搜索链接,@回复转换为个人资料链接。
html(“”+
tweet.html()
.replace(/((ftp | http | https):\/\/(\w+:{0,1}\w*@)(\S+)(:[0-9]+)(\/\\\/([\w!:?+=&%@!\-\/]))/gi.)
.替换(/(^|\s)#(\w+)/g,“1美元”)
.替换(/(^|\s)@(\w+)/g,$1')
+“
” ) .prepend(“”) .appendTo(“#tweets”) .fadeIn(); } }); }); });

别忘了切换到API 1.1。API 1.1使用count参数指定tweets限制。

向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();
      }
    });
  });
});
$(文档).ready(函数(){
//json调用twitter请求包含我们关键字的推文,在本例中为“谢菲尔德”
$.getJSON(“http://search.twitter.com/search.json?q=sheffield&rpp=2&callback=?,函数(数据){
//围绕结果循环
$.each(data.results,function(){
var text=this.text;
if(text.charAt(0)!=“@”){
//构造tweet并将append添加到我们的#tweets div
var tweet=$(“”).addClass('tweet').html(文本);
//分析推文文本,将URL转换为工作链接,将哈希标记转换为搜索链接,@回复转换为个人资料链接。
html(“”+
tweet.html()
.replace(/((ftp | http | https):\/\/(\w+:{0,1}\w*@)(\S+)(:[0-9]+)(\/\\\/([\w!:?+=&%@!\-\/]))/gi.)
.替换(/(^|\s)#(\w+)/g,“1美元”)
.替换(/(^|\s)@(\w+)/g,$1')
+“
” ) .prepend(“”) .appendTo(“#tweets”) .fadeIn(); } }); }); });

别忘了切换到API 1.1。API 1.1使用count参数指定推文限制。

此外,它仅显示最近发布的推文。是否可以显示以前发布的推文?请参阅上的搜索文档。查看不同类型tweet的result_type选项。此外,它仅显示最近发布的tweet。是否可以显示以前发布的推文?请参阅上的搜索文档。查看不同类型tweet的result_type选项。