Skip to content

Instantly share code, notes, and snippets.

@aerith
Created August 17, 2011 05:55
Show Gist options
  • Save aerith/1150895 to your computer and use it in GitHub Desktop.
Save aerith/1150895 to your computer and use it in GitHub Desktop.
instagr.am の API を利用するためのアクセストークンを取得して表示するスクリプト。JSON そのまま出力してるだけ。
#!/usr/bin/perl
use strict;
use warnings;
use Config::Pit;
use URI;
use URI::QueryParam;
use URI::Escape;
use LWP::UserAgent;
use HTTP::Cookies;
my $config = pit_get('instagr.am' , require => {
username => "your username on instagr.am",
password => "your password on instagr.am",
client_id => "your client_id on instagr.am",
client_secret => "your client_secret on instagr.am",
callback_url => "your callback_url on instagr.am"
});
my $agent = LWP::UserAgent->new();
$agent->cookie_jar(HTTP::Cookies->new);
my $login = $agent->post('https://instagram.com/accounts/login/', {
username => $config->{username},
password => $config->{password},
});
my $authorization_uri = URI->new('https://instagram.com/oauth/authorize/');
$authorization_uri->query_param_append(client_id => $config->{client_id});
$authorization_uri->query_param_append(redirect_uri => $config->{callback_url});
$authorization_uri->query_param_append(response_type => 'code');
my $authorization = $agent->get($authorization_uri);
my $confirmation = $agent->post($authorization->request->uri, {
allow => 'Yes',
});
my $callback_uri = URI->new($confirmation->headers->{location});
my $authorization_code = $callback_uri->query_param('code');
my $token_request = $agent->post('https://api.instagram.com/oauth/access_token', {
client_id => $config->{client_id},
client_secret => $config->{client_secret},
grant_type => 'authorization_code',
redirect_uri => $config->{callback_url},
code => $authorization_code,
});
print $token_request->content;
__DATA__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment