So far, I have been able to output live streaming data from Twitter. How to use this data? I am trying to insert it into a collection, but I am getting this error:
Error: Meteor code should always work inside Fiber. Try exchanging callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
I tried wrapping my code with fiber, but it did not work / or I am not wrapping the right part of the code. Also, I'm not sure if this is the right way to use streaming data in Meteor.
Posts = new Meteor.Collection('posts');
if (Meteor.isClient) {
Meteor.call("tweets", function(error, results) {
console.log(results);
});
}
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})
})
}
})
}
source
share