Skip to content

Instantly share code, notes, and snippets.

@ichigotake
Created April 22, 2012 01:42
Show Gist options
  • Save ichigotake/2440738 to your computer and use it in GitHub Desktop.
Save ichigotake/2440738 to your computer and use it in GitHub Desktop.
yancha api request sample
#!/usr/bin/env perl
#
## yanchaのAPIリクエストサンプル
##
## https://github.com/uzulla/yancha
##
use strict;
use warnings;
use utf8;
use feature qw(say);
use Encode;
use JSON;
use URI;
use LWP::UserAgent;
# API仕様
# https://github.com/uzulla/yancha/wiki/API%28%E4%BB%AE%29%E4%BB%95%E6%A7%98
my $uri = URI->new('http://yancha.hachiojipm.org:443/api/?tag=public&limit=1000');
my $ua = LWP::UserAgent->new();
my $res = $ua->get( $uri );
die $res->status_line if $res->is_error;
my $content = decode_json( $res->content );
say "id : created_at_ms : nickname : text\n";
foreach my$post(@$content) {
#print Dumper($post);
print sprintf("%d : %s: %s : %s\n ",
$post->{'id'},
$post->{'created_at_ms'},
encode('utf8', $post->{'nickname'}),
encode('utf8', $post->{'text'})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment