推特 + HTML5 webSocket API
有没有办法通过 HTML5 webSocket API (JavaScript) 连接到 Twitter?
目前 http://streamie.org/ 似乎正在做类似的事情,但他们正在通过http://local.streamie.org:8888/ 所以看起来他们正在运行 websocket。
JavaScript 部分非常清楚:
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) {
};
但是 Twitter 的 websocket 地址是多少?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Twitter 不提供 WebSocket 接口。如果您想通过 WebSocket 访问 Twitter Streaming API,则必须在自己的服务器上运行代理。
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.
这是一个演示网站,展示了 WebSockets 和 Twitter feed 的使用 - http://kaazing.me。您还可以从这里下载我们的 websocket 网关 - https://kaazing.com/download/ - 这也支持旧版浏览器,例如您可以在旧版浏览器中使用 WebSocket API。
但正如 Abraham 所说,您仍然需要构建自己的 Twitter 代理,因为它们不提供 WS 接口。
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.