With the Twitter stream API, you can only open one stream at a time. So, if you have multiple filters, the tweets in result will be mixed up, you'll need to do some post-processing.
This module lets you open multiple channels with there own filters, on the same stream. And then, you can add events to each of them individually, to listen to there results, like if you had open multiple streams.
You can see Topheman Datavisual which is a project I made, using this module for the Twitter Stream part.
npm install twitter-stream-channels
"consumer_key": "XXXXX""consumer_secret": "XXXXX""access_token": "XXXXXX""access_token_secret": "XXXXX"
You can find an API doc generated from the source code on http://labs.topheman.com/twitter-stream-channels/.
There are also examples in the repo, and the API is not that complicated ... But something that you could enjoy is the mocked version of the module that allows you to code without needing to connect to Twitter, since it has some connection limits over every 15 minutes (those limits are not greatly specified for the streaming API).
With this simple code, you retrieve your fake data (see also example) :
var credentials = ;;
And then, you can use it like :
var TwitterStreamChannelsMocked = ;var client =tweets:singleRun: false //so that you loop on your mocked tweets unless you call .stop() (if put at true, emulates a disconnection from twitter);// ... and then you can code like the example above (without connecting to twitter)
I use it for the unit tests of the module as well as when I code some application based on it.
.on('channels'): will listen to all the incoming tweets
.on('keywords/angularjs'): will only listen to the tweets where the keyword "angularjs" was matched
Two attributes are added to the tweet you retrieve :
Since the Twitter streaming filter API is case-insensitive, I lower case before matching, so the keywords matched you will find in
tweet.$channels['yourChannel'] are lower cased.
As specified in the Twitter streaming API :
The text of the Tweet and some entity fields are considered for matches. Specifically, the text attribute of the Tweet, expanded_url and display_url for links and media, text for hashtags, and screen_name for user mentions are checked for matches.
So I match your keywords not only against tweet.text but also against
screen_name when they are available (this is a work you won't have to bother to do ...)
The object returned by
(new require('twitter-stream-channels')(credentials)).streamChannels(options) extends the standard events.EventEmitter of nodejs, so you can use
If this persists, you can file an issue. But know that the twitter-stream-channels modules doesn't handle itself the network layer. It relies on twit for this part, so check if that doesn't come from it. If twit is upgraded with fixes, I will upgrade my module.
You can do anything the Twitter API offers, via the twit client which is exposed by getApiClient(). Once you retrieved the root client, you can call the API exposed by twit to interract with Twitter.
Yes, the v1 version does not introduce any breaking changes to the twitter-stream-channels API. The reasons of the version bump:
npm installto install the dependencies.
twitter.credentials.json, set your own credentials (you can get some at https://apps.twitter.com/app/new if you don't have any already)
npm run test
npm run test-watch(I set it up but don't use it for the moment)
twitter.credentials.jsonfile. Don't run them too many times (if you attempt too much connexion, your IP could be black listed from Twitter) :
npm run test-online(none for the moment and not so sure there should be any)
npm run yuidocwill generate doc into