• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
PerlでWeb API入門
 

PerlでWeb API入門

on

  • 5,290 views

 

Statistics

Views

Total Views
5,290
Views on SlideShare
4,788
Embed Views
502

Actions

Likes
1
Downloads
24
Comments
0

4 Embeds 502

http://yusukebe.com 437
http://kamawada.com 61
https://twitter.com 3
http://webcache.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    PerlでWeb API入門 PerlでWeb API入門 Presentation Transcript

    • Perl Web API 
 Web API Perl yusukebe 2010/07/23 Yokohama.pm#6 x PerlCasual#3
    • •  Perl •  Web API &&Perl •  / –  LWP::* •  –  20 : Web API ← –  30 : sugyan •  ( )
    • Web API •  API = Application Programming Interface –  / •  Web API API
    • Web API •  Twitter API •  Google Ajax API •  YouTube API •  Flickr API •  mixi API •  API •  etc…
    • / •  Web –  HTTP –  URI –  GET/POST –  JSON/XML etc.
    • 3 (GET ) 1.  URI 2.  GET 3. 
    • •  Twitter perl –  http://search.twitter.com/search.json?q=perl •  GET •  JSON • 
    • Twitter Search API •  Twitter •  http://dev.twitter.com/doc/get/search • 
    • API •  URI –  http://search.twitter.com/search.json •  –  JSON/atom •  –  GET •  –  q=perl
    • Web
    • URI •  ASCII •  URI •  http://search.twitter.com/search.json?q= %E3%81%8A%E3%81%AF %E3%82%88%E3%81%86
    • URI use URI;  use utf8;  my $query  = ' ';  my $uri    =  URI‐>new('http://search.twitter.com/search.json');  my $params = {      q           => $query,      result_type => 'popular',  };  $uri‐>query_form(%$params);  print "$urin";  http://search.twitter.com/search.json?  result_type=popular&q=%E3%81%8A%E3%81%AF %E3%82%88%E3%81%86
    • Web API •  LWP::UserAgent –  Others: LWP::Simple, URI::Fetch •  HTTP::Request •  –  GET/POST/PUT/DELETE/HEAD •  HTTP::Response
    • LWP::UserAgent use URI;  use LWP::UserAgent;  my $uri = URI‐>new('http://search.twitter.com/ search.json?q=perl');  my $ua  = LWP::UserAgent‐>new();  my $res = $ua‐>get( $uri );  die $res‐>status_line if $res‐>is_error;  print $res‐>content . "n"; 
    • •  cpanm JSON -> JSON::XS or JSON::PP •  JSON –  uXXXX Unicode ascii –  –  u304au306fu3088u3046
    • JSON use JSON qw( decode_json );  use Encode qw( encode_utf8 );  my $json_text =   '{"user":"yusukebe","message":"u304au306fu3088u3046"}';  my $ref = decode_json($json_text);  print encode_utf8("$ref‐>{user} : $ref‐>{message}n");  yusukebe :   
    • •  URI URI •  LWP::UserAgent URI / •  JSON
    • •  #yokohamapm use LWP::UserAgent;  use URI;  use JSON qw(decode_json);  use Encode qw(encode_utf8);  my $query  = '#yokohamapm';  my $uri  = URI‐>new('http://search.twitter.com/search.json'); 
    • my $params = {      q           => $query,      result_type => 'recent',  };  $uri‐>query_form(%$params);  my $ua   = LWP::UserAgent‐>new;  my $res  = $ua‐>get($uri);  die "Error: ". $res‐>status_line if $res‐>is_error;  my $json = $res‐>content;  my $ref  = decode_json($json);  for my $tweet ( @{ $ref‐>{results} } ) {  print encode_utf8("@$tweet‐>{from_user}: $tweet‐>{text}n");  } 
    • $ perl twitter_search.pl  @mazkeng:  ust  #yokohamapm  @hokke_mirin:  2 #perlcasual  #yokohamapm  @yusukebe:   #yokohamapm 
    • WebService::Simple use WebService::Simple;  use Data::Dumper;  my $query  = '#yokohamapm';  my $service = WebService::Simple‐>new(      base_url  => 'http://search.twitter.com/search.json',      response_parser => 'JSON',  );  my $res  = $service‐>get( { q => $query });  my $ref = $res‐>parse_response();  print Dumper $ref; 
    • •  Web API = •  Standing on the shoulders of giants - -
    • ? WEB+DB PRESS vol.58 2010 8 Perl Hackers Hub