Skip to content

Instantly share code, notes, and snippets.

@yusukebe
Created December 12, 2012 12:15
Show Gist options
  • Save yusukebe/4267325 to your computer and use it in GitHub Desktop.
Save yusukebe/4267325 to your computer and use it in GitHub Desktop.
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