themistral Posted March 10, 2010 Share Posted March 10, 2010 Guys, I have spent the last few days playing with the Twitter API's but I really don't know what I'm doing. I want a list of approx 50 of the newest tweets that updates an avatar every time a new mention of a particular word is mentioned. It's a bit like the fixoutlook.org background. I guess I need to use the streaming API, but I am finding the documention really difficult to understand - I've never used an API before. Do I need to save the data to a database first? Thanks! Quote Link to comment Share on other sites More sharing options...
themistral Posted March 10, 2010 Author Share Posted March 10, 2010 Guys, Assuming I do have to store the data in a database, I am having a problem <?php include_once('config.php'); $opts = array( 'http'=>array( 'method' => "POST", 'content' => 'track='.WORDS_TO_TRACK, ) ); $context = stream_context_create($opts); while (1){ $instream = fopen('http://'.TWITTER_USERNAME.':'.TWITTER_PASSWORD.'@stream.twitter.com/1/statuses/filter.json','r' ,false, $context); while(! feof($instream)) { if(! ($line = stream_get_line($instream, 20000, "\n"))) { continue; }else{ $tweet = json_decode($line); //Clean the inputs before storing $id = mysql_real_escape_string($tweet->{'id'}); $text = mysql_real_escape_string($tweet->{'text'}); $screen_name = mysql_real_escape_string($tweet->{'user'}->{'screen_name'}); $followers_count = mysql_real_escape_string($tweet->{'user'}->{'followers_count'}); $avatar = mysql_real_escape_string($tweet->{'user'}->{'profile_image_url'}); //We store the new post in the database, to be able to read it later // code to add to database here flush(); } } } ?> config.php contains twitter account details and search term. I am using the above code to generate the stream, but $id = mysql_real_escape_string($tweet->{'id'}); shows the same id for every post. Can anyone offer any advice? Please - I am desperate to understand this! Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.