【发布时间】: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