【问题标题】:Twitter streaming api node.js - Slow the stream downTwitter 流 api node.js - 减慢流
【发布时间】:2016-04-18 17:42:23
【问题描述】:

我正在制作一个应用程序,允许您搜索一个位置,然后显示与该位置相关的过滤推特提要,问题在于像“伦敦”这样的搜索有太多实时推文,提要移动得如此之快以至于你无法阅读它们。

我不知道我是否应该停止并启动套接字?或者将所有推文推入前面的数组中,然后附加它们,但数组很容易变得太大。此外,有些搜索会非常慢,因此不必一直发生这种情况。

我已经用 node 和 express 构建了它,如果数据会被欣赏的话,任何想法如何处理这个数量。

示例代码 - 后端

    var place = [ '-122.75', '36.8', '-121.75', '37.8' ]
    var stream = twitter.stream('statuses/filter', { locations: place, language: 'en' })

   stream.on('tweet', function (tweet) {
     console.log(tweet)
   })

   io.on('connect', function(socket) {

  // this is coming from the twit module. 
  // 'tweet' is one of the events it listens to
     stream.on('tweet', function(status) {

   // this is our own channel we set up to to send the tweets down to the client
    var data = {};
    data.name = status.user.name;
    data.screen_name = status.user.screen_name;
    data.text = status.text;
    data.user_profile_image = status.user.profile_image_url;

    socket.emit('statuses', data);
  });
});

【问题讨论】:

    标签: javascript node.js api twitter socket.io


    【解决方案1】:

    您可以尝试使用 readable.pause() 函数 - 这里有更多参考:https://nodejs.org/api/stream.html#stream_readable_pause

    基本上,您可以使用 .pause() 暂停流,当您能够再次阅读时,您可以调用 .resume()。

    另一个想法是以某种方式过滤数据。当你放慢速度时,一个小时后你将落后于“主流”一个小时。

    【讨论】:

      猜你喜欢
      • 2013-04-05
      • 2012-09-02
      • 2019-09-23
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-04
      • 2018-03-13
      相关资源
      最近更新 更多