5

Is there a way of connecting to Twitter through the HTML5 webSocket API (JavaScript)?

Currently http://streamie.org/ seems to be doing something like that but they are leading it through http://local.streamie.org:8888/ so it looks like they are running the websocket.

The JavaScript part is quite clear:

websocket = new WebSocket('ws://echo.websocket.org/');


websocket.onopen = function(event) {

    websocket.send('hello from client');

    console.log('CONNECTED');
};

websocket.onclose = function(event) {

    console.log('DISCONNECTED');
};

websocket.onmessage = function(event) {

    console.log(event.data);
};

websocket.onerror = function(event) {


};

But what's the websocket address for Twitter?

DADU
  • 6,482
  • 7
  • 42
  • 64

2 Answers2

4

Twitter does not provide a WebSocket interface. You will have to run a proxy on your own server if you want to access the Twitter Streaming API through WebSockets.

abraham
  • 46,583
  • 10
  • 100
  • 152
  • Thank you. There is no such service that runs this for you? – DADU Mar 16 '11 at 03:27
  • 2
    I know that [Superfeedr supports WebSockets](http://blog.superfeedr.com/websockets-and-comet/) so you might be able to use them depending on if they have the Twitter data you need. You might also be able to use [DataSift's WebSocket API](http://support.datasift.net/help/kb/streaming-api/websocket-streaming). – abraham Mar 16 '11 at 07:04
  • I think DataSift's WebSocket API is just what we need. Thanks. – DADU Mar 16 '11 at 16:38
4

Here is a demo site showing the use of WebSockets and a Twitter feed - http://kaazing.me. You can also download our websocket gateway from here - https://kaazing.com/download/ - which also supports older browsers e.g. you can use the WebSocket APIs with older browsers.

But as Abraham said, you still need to build your own proxy to Twitter since they do not provide a WS interface.

Michel Floyd
  • 18,793
  • 4
  • 24
  • 39
Jonas
  • 49
  • 1
  • hey Jonas your library looks like excellent stuff! but I don't know if I understand very well if they will be of use for me. I have an app that already uses oauth and i'd like to connect to the twitter streaming service. Can I do it with any of the client JS libraries included in your bundles without installing anything on server? – rupps Aug 08 '13 at 16:34