到目前为止,我已经能够从Twitter下载流式实时数据.我该如何使用这些数据?我试图将其插入集合,但我收到此错误:
错误:流星代码必须始终在光纤内运行.尝试使用Meteor.bindEnvironment包装传递给非Meteor库的回调.
我尝试用光纤包装我的代码,但它不起作用/或者我没有包装正确的代码部分.此外,我不确定这是否是在Meteor中使用流数据的正确方法.
Posts = new Meteor.Collection('posts');
if (Meteor.isClient) {
Meteor.call("tweets", function(error, results) {
console.log(results); //results.data should be a JSON object
});
}
if (Meteor.isServer) {
Meteor.methods({
tweets: function(){
Twit = new TwitMaker({
consumer_key: '...',
consumer_secret: '...',
access_token: '...',
access_token_secret: '...'
});
sanFrancisco = [ '-122.75', '36.8', '-121.75', '37.8' ];
stream = Twit.stream('statuses/filter', { locations: sanFrancisco });
stream.on('tweet', function (tweet) {
userName = tweet.user.screen_name;
userTweet = tweet.text;
console.log(userName + " says: " + userTweet);
Posts.insert({post: tweet})
})
}
})
}
Run Code Online (Sandbox Code Playgroud)