Twitter Stream API with PHP/Javascript Implimentation
I am trying to create website to show a live twitter feed concerning a particular hash tag, say #baseball or from a particular user @twitter, my filter looks like #baseball OR @twitter
Now I have done implementation using Phirehose but I want to use AJAX instead so that i can contain the live stream in a fixed div on my website. I searched a lot, and guess many people have done this but I am not able to find any reference code or example of how to do it.
PHP code 开发者_C百科I am using:
require_once('../lib/Phirehose.php');
class FilterTrackConsumer extends Phirehose
{
public function enqueueStatus($status)
{
$data = json_decode($status, true);
if (is_array($data) && isset($data['user']['screen_name'])) {
echo $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n";
}
}
}
// Start streaming
$sc = new FilterTrackConsumer('abc', 'abc', Phirehose::METHOD_FILTER);
$sc->setTrack(array('@twitter', '#baseball'));
$sc->consume();
I need something similar with Javascript & PHP. Or how to style the output here. Help would be appreciated
The best way to do a live stream update with AJAX is with polling.
Set a timer, make an AJAX request to the page you just posted, add the response to the page with javascript :)
Here are a few pages to make the ajax polling, even tho it is pretty simple in nature, and a setTimeout()
would be good enough for the job
http://www.nickriggs.com/posts/simple-ajax-polling-plugin-for-jquery/
https://github.com/RobertFischer/JQuery-PeriodicalUpdater/
Good luck !
精彩评论