Track Your Favorite Topic on Twitter: A PHP CLI Tool

Sunday, January 3rd, 2010

Tags: ,

Here’s a little php utility that will let you watch the Twitter public time line for your favorite topic. This is specially helpful for those who want to build some tracking application on the basis of the twitter streaming APIs.

Here’s the source:

<?php
$topic = $argv[1];
if(empty ($topic)) {
    $topic = "php";
}
$username = "twitter_username";
$password = "twitter_password";
$fp = fopen("http://{$username}:{$password}@stream.twitter.com/1/statuses/filter.json?track={$topic}","r");
while( $data = fgets($fp) ) {
    $tweet = json_decode($data,true);
    if(!empty($tweet['text'])) {
        echo $tweet['user']['screen_name'].": ".$tweet['text']." \n -------------------- \n";
    }
}
?>

Run this script with the keyword as the argument:

php twitter.php keyword

5 Responses to “Track Your Favorite Topic on Twitter: A PHP CLI Tool”

  1. [...] This post was Twitted by masnun [...]

  2. [...] more from the original source: Track Your Favorite Topic on Twitter: A PHP CLI Tool « maSnun.com [...]

  3. [...] Read the original: Track Your Favorite Topic on Twitter: A PHP CLI Tool « maSnun.com [...]

  4. [...] This post was mentioned on Twitter by Abu Ashraf Masnun, Telletto. Telletto said: maSnun says… Track Your Favorite Topic on Twitter: A PHP CLI Tool: Here’s a little php utility that will let yo… http://bit.ly/88tABd [...]

  5. Rosio Mettler says:

    Twitter gave me a HUGE boost in the Google rankings

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">