php - How to retrieve Twitter search results dynamically using Ajax? -
i'm building twitter application depends on retrieving twitter search results. works fine still need update page new tweets.
how let page refreshes dynamically twitter widgets, show new tweets ?
here code, please show me how, because tired many scripts , doesn't work me.
twitter class
<?php class twitter { public function __construct(){ } public function searchresults( $search = null ) { $url = "http://search.twitter.com/search.atom?q=" . urlencode( $search ) . "&lang=en&rpp=50"; $curl = curl_init(); curl_setopt( $curl, curlopt_url, $url ); curl_setopt( $curl, curlopt_returntransfer, 1 ); $result = curl_exec( $curl ); curl_close( $curl ); $return = new simplexmlelement( $result ); return $return; } } ?>
test class
<?php require_once("twitter.class.php"); $twitter = new twitter; $results = $twitter->searchresults("usa"); foreach( $results->entry $result ) { echo "<h3><a href=\"". $result->author->uri ."\">". $result->author->name ."<a/></h3><img src=\"". $result->link[1]->attributes()->href ."\" style=\"float: left;\"><p>". $result->content."</p><div style=\"clear:both;\"> </div>"; } ?>
. .
waiting response :)
you poll changes through javascript / ajax, setting timer calls function in test class returns list of tweets. example (using jquery because no javascript expert):
$(function() { function fetchtweets() { $.ajax({ url: "testclass.php", success: function(data) { // replace contents of 1 element data } } setinterval(fetchtweets(), 60000); }
Comments
Post a Comment