【问题标题】:Custom Twitter Widget - Limit the number of tweets自定义 Twitter 小部件 - 限制推文数量
【发布时间】:2013-05-03 20:50:32
【问题描述】:

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

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

在教程中,我收到了推文。 但我想将推文的数量限制在 2 条以内。

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

【问题讨论】:

    标签: json widget twitter


    【解决方案1】:

    在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。 See API 1.1 search documentation。 API 1.1 使用计数参数来指定推文限制。

    【讨论】:

    • 它还只显示最近发布的推文。有什么方法可以显示以前发布的推文?。
    • 请参阅dev.twitter.com/docs/api/1/get/search 上的搜索文档。查看不同类型推文的 result_type 选项。
    猜你喜欢
    • 2014-07-23
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 2012-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多