Created
December 12, 2012 12:15
-
-
Save yusukebe/4267325 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use LWP::UserAgent; | |
use URI; | |
use JSON qw/decode_json/; | |
use utf8; | |
my $query = '猫 instagr.am'; # 検索語 | |
# リクエストURLを構築 | |
my $uri = URI->new('http://search.twitter.com/search.json'); | |
$uri->query_form( | |
q => $query, | |
include_entities => 1, | |
); | |
my $ua = LWP::UserAgent->new(); | |
# APIへアクセス | |
my $res = $ua->get($uri); | |
# JSONをPerlの構造体へデコード | |
my $ref = decode_json($res->decoded_content); | |
# ツイートオブジェクトをループさせてInstagramの画像URLを抽出 | |
for my $tweet (@{$ref->{results}}) { | |
my $insta_url = $tweet->{entities}{urls}[0]{expanded_url}; | |
my ($id) = $insta_url =~ m!http://instagr.am/p/(.+?)/!; | |
next unless $id; | |
print "http://instagr.am/p/$id/media?size=m\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment