twitter-stream-client
v0.11.3
Published
A daemon listening to Twitter streaming API
Downloads
18
Readme
TwitterStreamClient is a client for the Twitter Streaming API
Quick start
To install TwitterStreamClient, run:
npm install twitter-stream-client
A simple Twitter Stream client would be:
var TwitterClient = require('twitter-stream-client');
var twitterClient = new TwitterClient ({
OAuth: {
consumerKey: 'TWITTER CONSUMER KEY',
consumerSecret: 'TWITTER CONSUMER SECRET',
},
keywords: '#hashtag',
accessToken: 'TWITTER ACCESS TOKEN',
accessTokenSecret: 'TWITTER ACCESS TOKEN SECRET'
});
twitterClient.on('newtweet', function (tweet) {
console.log(tweet.text);
});
Events
TwitterStreamClient is an EventEmitter and sends the following events:
- connected: when we have a response from Twitter
- twitterdown: when we did not get the keep alive tick from Twitter for longer than keepAliveTime (see API#constructor)
- newtweet: when we have a new tweet from Twitter, the parsed tweet is passed as a parameter to the callback
- missedtweets: when twitter sends a "limit" error, we emit this event with the number of missed tweets on this particular time (not the total)
- error: when the connection request gets an error code as a response or Twitter sends a string that is not JSON
API
TwitterClient (options, proxy)
TwitterClient is the constructor and has two arguments:
options
is a hash which must contain:
OAuth
, a hash containingconsumerKey
(you Twitter consumer key) andconsumerSecret
(your Twitter consumer secret)keywords
(string), a comma-separated list of keywords to wtach on TwitteraccessToken
(string), your Twitter access tokenaccessTokenSecret
(string), your Twitter access token secret
options
can also contain:
keepAliveTime
(integer), default 64000, if Twitter does not send a keep alive tick after this duration, we consider the connection is lost and sendtwitterdown
event and restart the clienttrackRequest
(string), default'/1.1/statuses/filter.json?stall_warnings=true&track'
, can be used to change the streaming API we usehost
(string), default'stream.twitter.com'
,port
(string), default'443'
,languagesFilter
(string), comma separated list of languages (Twitter codes) to add as filter to the request default''
If set proxy
is a hash which must contain:
host
(string), the host of your proxyport
(string), the port of your proxy
connect ()
Actually connects to Twitter API, if you save the tweets in the listener of newtweet
event, the database must be ready and connected before calling connect().
disconnect ()
Disconnect from Twitter API
Licence
MIT