This is not the right way to access the streaming API. John K. is going to yell at you. :) You should be making a continuous connection to the streaming API and keeping it open. This is generally done with a background PHP process that is launched with a command like: nohup php [your PHP script] &
Your script should make a connection and keep it open. I use Fenn Bailey's Phirehose library to handle the connection. It does all the work for you. Your inserts are probably failing because you are adding raw tweet text as it is delivered by the API. This is going to have quote marks and other characters that will cause the insert to fail. I use: $tweet_object = json_decode($status); $raw_tweet = base64_encode(serialize($tweet_object)); Then I insert the $raw_tweet value. This has never failed. I have an open source library that is heavily documented that explains this process. It uses PHP, Phirehose and MySQL, so it is a good starting point for you to build on: http://140dev.com/free-twitter-api-source-code-library/twitter-database-server/ On Thu, Dec 9, 2010 at 3:24 AM, planb <[email protected]> wrote: > > Hey Guys, > > I'm trying to stream in any tweets related to my keyword but for some > reason they won't go into the my_sql database any thoughts? The other > day it suddenly started working....now its not working again....i dont > get it. > > $fp = fopen("http://" . $username . ":" . $password . > "@stream.twitter.com/1/statuses/filter.json?track=" . $keyword , 'r'); > > while($data = fgets($fp)) > { > $tweet = json_decode($data, true); > > $user = $tweet['user']['screen_name']; > $text = $tweet['text']; > > $sql = "INSERT INTO dbname (user,tweet) > VALUES('$user','$tweet')"; > mysql_query($sql); > } > > fclose($fp); > > -- > Twitter developer documentation and resources: http://dev.twitter.com/doc > API updates via Twitter: http://twitter.com/twitterapi > Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list > Change your membership to this group: > http://groups.google.com/group/twitter-development-talk -- Adam Green Twitter API Consultant and Trainer http://140dev.com @140dev -- Twitter developer documentation and resources: http://dev.twitter.com/doc API updates via Twitter: http://twitter.com/twitterapi Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list Change your membership to this group: http://groups.google.com/group/twitter-development-talk
