簡體   English   中英

Twitter流API節點-降低流速度

[英]Twitter streaming api node.js - Slow the stream down

我正在制作一個應用程序,允許您搜索位置,然后顯示與該位置相關的已過濾Twitter提要,問題出在“倫敦”之類的搜索中,實時推文太多,提要移動得很快,以至於您無法閱讀他們。

我不知道是否應該停止並啟動套接字? 或將所有tweet推入前面的數組中,然后附加它們,但是數組很容易變得太大。 另外,某些搜索的速度實際上會很慢,因此不必始終如此。

我已經用node構建了它,並表達了任何想法,如果可以理解數據,該如何處理這個數量。

示例代碼-后端

    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);
  });
});

您可以嘗試使用可讀.pause()函數-此處有更多參考: https : //nodejs.org/api/stream.html#stream_visible_pause

基本上,您可以使用.pause()暫停流,當您能夠再次閱讀時,可以調用.resume()。

另一個想法是以某種方式過濾數據。 當您放慢速度時,一個小時后,您將比“主流”落后一個小時。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM