Twitter + HTML5 webSocket API

橙三吉。 提交于 2020-01-03 13:00:41

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5313736/twitter-html5-websocket-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!