Skip to content

Instantly share code, notes, and snippets.

@chiral
Created October 8, 2011 18:51
Show Gist options
  • Save chiral/1272694 to your computer and use it in GitHub Desktop.
Save chiral/1272694 to your computer and use it in GitHub Desktop.
Twitter API sample
use JSON;
use Encode;
if (@ARGV<1) { print "usage: $0 user_id [page]\n"; exit(0); }
my $url="http://twitter.com/statuses/user_timeline.json?id=$ARGV[0]";
$url.="\\&page=$ARGV[1]" if ($ARGV[1]);
open(F,"wget $url -O -|");my $j=<F>;close(F);
my $j=~s/\\u([0-9a-f]{4})/u16u8($1)/egi;
my $d=JSON::decode_json($j);
foreach(@$d){
print "$_->{id} from $_->{source}\n";
print "$_->{created_at}\n";
print e8($_->{text})."\n\n";
}
sub e8{Encode::encode('utf8',$_[0])}
sub u16u8{e8(Encode::decode('utf16be',pack('H*',$_[0])))}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment