Last active
March 25, 2020 07:19
-
-
Save hecomi/31acf4a0e390fbed3b8d to your computer and use it in GitHub Desktop.
twitter websocket sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm install twitter ws | |
$ node twitter-websocket |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Twitter = require('twitter'); | |
var client = new Twitter({ | |
consumer_key : 'XXXXXXXXXXXXXXXXXXXXXXXXX', | |
consumer_secret : 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', | |
access_token_key : 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', | |
access_token_secret : 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | |
}); | |
var WebSocketServer = require('ws').Server; | |
var wss = new WebSocketServer({ port: 3000 }); | |
client.stream('statuses/filter', {track: 'oculus rift'}, function(stream) { | |
wss.on('connection', function connection(ws) { | |
stream.on('data', function(tweet) { | |
ws.send(tweet); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment