Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Created December 9, 2010 23:00
Show Gist options
  • Save emad-elsaid/735471 to your computer and use it in GitHub Desktop.
Save emad-elsaid/735471 to your computer and use it in GitHub Desktop.
Getting latest tweets using php
<?php
// getting the latest tweets
$tweets_json = file_get_contents("http://twitter.com/statuses/user_timeline/blaz_boy.json?callback=t&count=100");
// trimming the retrieved text to be pure json for PHP
$tweets_json = substr($tweets_json, 2, strlen($tweets_json)-4);
// convert to array of objects
$object = json_decode($tweets_json);
// the final desired output
$text = '';
// traverse through all the object array
foreach( $object as $o )
$text = $text.$o->text."\r\n";
// write output to file
file_put_contents( "output.txt", $text );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment