1

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

http://www.evoluted.net/thinktank/web-development/creating-your-own-twitter-trends-widget

就像在教程中一样,我得到了推文。但我想将推文的数量限制为 2 条。

网站 - http://testingweddev.comli.com/

4

1 回答 1

1

rpp=在url中添加参数

$(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 使用计数参数来指定推文限制。

于 2013-05-03T12:41:58.390 回答