最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Utilizing Twitter's Streaming API w jQuery? - Stack Overflow

programmeradmin7浏览0评论

Twitter's Streaming API seems to provide a way to receive realtime tweets without constantly polling for new data. Would it be possible to make use of this API using jQuery (or maybe falling back to pure JS)?

As far as I can tell, there's no built-in way for jQuery to stream an HTTP request with JSON. Is that correct, or did I miss something? If this ability isn't built-in, has anyone already tackled this problem with a plugin or example?

Update: From what I can gather, HTML 5's support for WebSockets would likely be the best approach to achieve this. Unfortunately that means mainstream patibility is still at least a few years out. As far as I know, these browser versions currently support WebSockets in some fashion:

  • WebKit 5 (Safari/Chrome)
  • Firefox 4
  • IE9 (Eventually)

Twitter's Streaming API seems to provide a way to receive realtime tweets without constantly polling for new data. Would it be possible to make use of this API using jQuery (or maybe falling back to pure JS)?

As far as I can tell, there's no built-in way for jQuery to stream an HTTP request with JSON. Is that correct, or did I miss something? If this ability isn't built-in, has anyone already tackled this problem with a plugin or example?

Update: From what I can gather, HTML 5's support for WebSockets would likely be the best approach to achieve this. Unfortunately that means mainstream patibility is still at least a few years out. As far as I know, these browser versions currently support WebSockets in some fashion:

  • WebKit 5 (Safari/Chrome)
  • Firefox 4
  • IE9 (Eventually)
Share Improve this question edited Aug 4, 2010 at 16:50 Wilco asked Jul 22, 2010 at 19:27 WilcoWilco 33.4k49 gold badges132 silver badges161 bronze badges 3
  • This seems interesting, but at least for the Twitter streams you have to authenticate the request so wouldn't you be exposing your credentials by using JavaScript to get the stream? Otherwise, I think this JSON stream is a pretty cool idea and I'm going to look more into it. – Sandro Commented Jul 22, 2010 at 19:53
  • That's a good point that I hadn't discovered yet. In my particular case it wouldn't be a problem since I'm serving the page locally (and only accessible from localhost) and embedding it on my desktop. – Wilco Commented Jul 22, 2010 at 20:06
  • Do you have an example utilising the streaming api with websockets or jquery that you could share or provide some useful links that you used? – Sonoman Commented Jul 28, 2011 at 23:15
Add a ment  | 

2 Answers 2

Reset to default 4

HTML5 WebSockets would probably be the best choice.

It is possible to use WebSockets for modern browsers and Flash fallback for unsupported browsers.

This one supports alle browsers: http://jwebsocket/index.htm?page=browsers.htm

You can also try this on, but not tested on IE6: http://github./gimite/web-socket-js

This page might be of interest:

http://ajaxpatterns/HTTP_Streaming#Refactoring_Illustration

发布评论

评论列表(0)

  1. 暂无评论