Twitter Search Streaming API Example

Posted By: Matpal - June 19, 2011
Twitter provides its Streaming API for search. Following code will help you to stream the search data ,

<?php
    $opts = array(
        'http'=>array(
            'method'    =>    "POST",
            'content'    =>    'track=flickr',
        )
    );
    $context = stream_context_create($opts);
    $instream = fopen('http://USERNAME:PASSWORD@stream.twitter.com/1/
statuses/filter.json','r' ,false, $context);
    while(! feof($instream)) {
        if(! ($line = stream_get_line($instream, 20000, "\n"))) {
            continue;
        }else{
            //print_r(json_decode($line));
            $tweet = json_decode($line);
            print $tweet->{'text'}."\n";
            flush();
        }
    }
?>

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.