TwitterStreamChannels
Summary
This is your main point of entry to the whole module.
Manage filters on multiple channels on the same Twitter Stream
var TwitterStreamChannels = require('twitter-stream-channels');
var credentials = require('./my.twitter.credentials.json');
var client = new TwitterStreamChannels(credentials);
var channels = {
"languages" : ['javascript','php','java','python','perl'],
"js-frameworks" : ['angularjs','jquery','backbone','emberjs'],
"web" : ['javascript','nodejs','html5','css','angularjs']
};
var stream = client.streamChannels({track:channels});
stream.on('channels/languages',function(tweet){
console.log('>languages',tweet.text);//any tweet with 'javascript','php','java','python','perl'
});
stream.on('channels/js-frameworks',function(tweet){
console.log('>frameworks',tweet.text);//any tweet with 'angularjs','jquery','backbone','emberjs'
});
stream.on('channels/web',function(tweet){
console.log('>web',tweet.text);//any tweet with 'javascript','nodejs','html5','css','angularjs'
});
//If you want, you can listen on all the channels and pickup the $channels added by the module
//It contains the channel and the keywords picked up in the tweet
//stream.on('channels',function(tweet){
// console.log(tweet.$channels,tweet.text);//any tweet with any of the keywords above
//});
//If you're really picky, you can listen to only some keywords
//stream.on('keywords/javascript',function(tweet){
// console.log(tweet.text);//any tweet with the keyword "javascript"
//});
setTimeout(function(){
stream.close();//closes the stream connected to Twitter
console.log('>stream closed after 100 seconds');
},100000);
Constructor
TwitterStreamChannels
Syntax
Summary
Parameters:
Returns:
Item Index
Methods
- getApiClient
- getMockedClass static
- launchMockDataRetriever static
- streamChannels
Methods
getApiClient
Syntax
getApiClient
()
Twit
Summary
Returns a Twitter API client on which you can do pretty much what you want. More here https://github.com/ttezel/twit
Returns:
getMockedClass
Syntax
Summary
Returns a mocked object of TwitterStreamChannels on which you will be able to play your scenarios offline with your own mocked tweets
Returns:
launchMockDataRetriever
Syntax
Summary
This will allow you to create your own json data mocks
Keep in mind this class is not designed to retrieve lots of tweets on long duration.
It was only designed to ease the creation of your data mocks to use after with TwitterStreamChannels.getMockedClass()
More infos in the README on the github repo
Parameters:
-
credentials
Object -
options
Object-
track
Arrayarray of keywords to track
-
output
Stringfilepath of the json file where to put the retrieved tweets
-
[maxNumber=200]
String optionalmaximum number of tweets that will be retrieved (default 200 / max 500)
-
[timeout=100000]
String optionalmaximum delay after the stream will close whatever number of tweets are captured (default 100 000ms)
-
Returns:
streamChannels
Syntax
Summary
Opens a Twitter Stream and returns you an other one on which you'll be able to attach events for each channels
Parameters:
-
options
ObjectYou can use the same filter options as described in the Twitter stream API for
statuses/filter
https://dev.twitter.com/docs/api/1.1/post/statuses/filter-
track
Object | ArrayPass an object describing your channels. If you don't want to use channels, you can pass directly an array of keywords.
-
[follow]
String optionalA comma separated list of user IDs, indicating the users to return statuses for in the stream
-
[locations]
String optionalSpecifies a set of bounding boxes to track. More about how to format this parameter here : https://dev.twitter.com/docs/streaming-apis/parameters#locations
-
[enableChannelsEvents=true]
Boolean optionalIf true, will fire the events like 'channels/channelName'
-
[enableRootChannelsEvent=true]
Boolean optionalIf true, will fire the event 'channels'
-
[enableKeywordsEvents=false]
Boolean optionalIf true, will fire the events 'keywords/keywordName' (disabled by default)
-