Newb Question for twitter streaming


#1

Meteor Newb here. I’m digging through the packages and I’m interested in streaming tweets. I found the mrt:user-stream package and see that there is a code example for streaming tweets to the console. Which file would I put this block of code in to get the tweets to stream via console. Do I need to create a server folder and put this code in there? any help is appreciated. Thanks

here is the code (I already have all my twitter keys):

var Stream = require(‘user-stream’);
var stream = new Stream({
consumer_key: ‘’,
consumer_secret: ‘’,
access_token_key: ‘’,
access_token_secret: ‘’
});

//create stream
stream.stream();

//listen stream data
stream.on(‘data’, function(json) {
console.log(json);
});


#2

Just try it :smile: But yes, this would need to go into a file in /server. And you don’t have to require user-stream. That’s already been done. So just leave out the first line, and save your file.
: )


#3

Thanks for the reply! I tried deleting that line and not its telling me that Stream is not defined.


#4

I just created a new Meteor project to test it and it worked great. Should be quite clear what to do and the only thing I can imagine is that you forgot to add the package. If not that’s what I did:

  1. meteor create twitter-test

  2. Remove all files from twitter-test/

  3. Create a folder server with a file twitter.js inside

  4. Run meteor add mrt:user-stream

  5. Paste this code into the twitter.js file, without the first line (var Stream = require('user-stream');)

  6. Go to http://apps.twitter.com and create an app, or get the keys you already have

  7. Insert keys into the Stream configuration

  8. Set request parameters (here and here). I changed stream.stream() to

    stream.stream({
    with: ‘meteorjs’
    });

  9. Run meteor and tweet the MDG guys something nice

  10. The tweet gets logged.


#5

Thanks, fvg! It works. Thanks again for the help.