Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $username = 'user';
- $password = 'pass';
- $count = 1;
- do {
- $fp = fsockopen("stream.twitter.com", 80, $errno, $errstr, 30);
- if (!$fp) {
- echo "$errstr ($errno)\n";
- } else {
- $out = "GET /gardenhose.json HTTP/1.1\r\n";
- $out .= "Host: stream.twitter.com\r\n";
- $out .= "User-Agent: UserAgent\r\n";
- $out .= "Authorization: Basic " . base64_encode($username . ':' . $password)."\r\n";
- $out .= "Connection: Close\r\n\r\n";
- fwrite($fp, $out);
- while (!feof($fp)) {
- $line = fgets($fp, 4096);
- if ($count > 5) {
- if (trim($line) != '') {
- $tweet_obj = json_decode(trim($line));
- }
- }
- else {
- // view the first 5 lines (headers): uncomment the below line
- // echo trim($line) . "\n";
- }
- $count++;
- }
- fclose($fp);
- }
- } while (true);
Add Comment
Please, Sign In to add comment