view release on metacpan or search on metacpan
b) cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).
c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.
d) You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
client_secret => $client_secret,
redirect_uri => 'http://localhost',
});
# Authenticated user feed
my $my_user = $instagram->user;
my $feed = $my_user->feed( count => 5 );
for my $media ( @$feed ) {
printf "Caption: %s\n", $media->caption;
printf "Posted by %s at %s (%d likes)\n\n", $media->user->username, $media->created_time, $media->likes;
}
DESCRIPTION
This module implements an OO interface to Instagram REST API.
Authentication
Instagram API uses the OAuth2 for authentication, requering a
"client_id" and "client_secret". See
<http://instagr.am/developer/register/> for details.
my $instagram = API::Instagram->new({
client_id => 'xxxxxxxxxx',
client_secret => 'xxxxxxxxxx',
redirect_uri => 'http://localhost',
scope => 'basic',
response_type => 'code',
granty_type => 'authorization_code',
});
print $instagram->get_auth_url;
Authenticate
After authorization, Instagram will redirected the user to the URL in
"redirect_uri" with a code as an URL query parameter. This code is
needed to obtain an acess token.
$instagram->code( $code );
my $access_token = $instagram->get_access_token;
Request
With the access token its possible to do Instagram API requests using
the authenticated user credentials.
$instagram->access_token( $access_token );
my $me = $instagram->user;
print $me->full_name;
METHODS
new
my $instagram = API::Instagram->new({
client_id => $client_id,
client_secret => $client_secret,
redirect_uri => 'http://localhost',
scope => 'basic',
response_type => 'code',
granty_type => 'authorization_code',
"response_type" and "granty_type" do no vary. See
<http://instagram.com/developer/authentication/>.
By default, API::Instagram caches created objects to avoid duplications.
You can disable this feature setting a true value to "no_chace"
parameter.
instance
my $instagram = API::Instagram->instance;
print $instagram->user->full_name;
or
my $instagram = API::Instagram->instance({
client_id => $client_id,
client_secret => $client_secret,
redirect_uri => 'http://localhost',
});
Returns the singleton instance of API::Instagram.
Note: if no instance was created before, creates a new API::Instagram
object initialized with arguments provided and then returns it.
get_auth_url
my $auth_url = $instagram->get_auth_url;
print $auth_url;
Returns an Instagram authorization URL.
get_access_token
my $access_token = $instagram->get_access_token;
or
my ( $access_token, $auth_user ) = $instagram->get_access_token;
Returns an API::Instagram::Search object, capable to search for the
given type.
Where type can be: "user", "media", "tag" or "location".
See API::Instagram::Search for more details and examples.
popular_medias
my $medias = $user->popular_medias( count => 3 );
print $_->caption . $/ for @$medias;
Returns a list of API::Instagram::Media objects of Instagram most
popular media at the moment.
AUTHOR
Gabriel Vieira <gabriel.vieira@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Gabriel Vieira.
lib/API/Instagram.pm view on Meta::CPAN
$params->{access_token} = $self->access_token;
# Prepares the URL
my $uri = URI->new( $self->_endpoint_url );
$uri->path_segments( $uri->path_segments, split '/', $url );
$uri->query_form($params);
$url = $uri->as_string;
}
# For debugging purposes
print "Requesting: $url$/" if $self->_debug;
# Treats response content
my $res = decode_json $self->_ua->$method( $url, [], $params )->decoded_content;
# Verifies meta node
my $meta = $res->{meta};
carp "$meta->{error_type}: $meta->{error_message}" if $meta->{code} ne '200';
use Data::Dumper;
# die Dumper $res;
lib/API/Instagram.pm view on Meta::CPAN
client_secret => $client_secret,
redirect_uri => 'http://localhost',
});
# Authenticated user feed
my $my_user = $instagram->user;
my $feed = $my_user->feed( count => 5 );
for my $media ( @$feed ) {
printf "Caption: %s\n", $media->caption;
printf "Posted by %s at %s (%d likes)\n\n", $media->user->username, $media->created_time, $media->likes;
}
=head1 DESCRIPTION
This module implements an OO interface to Instagram REST API.
=head2 Authentication
Instagram API uses the OAuth2 for authentication, requering a C<client_id> and
lib/API/Instagram.pm view on Meta::CPAN
my $instagram = API::Instagram->new({
client_id => 'xxxxxxxxxx',
client_secret => 'xxxxxxxxxx',
redirect_uri => 'http://localhost',
scope => 'basic',
response_type => 'code',
granty_type => 'authorization_code',
});
print $instagram->get_auth_url;
=head3 Authenticate
After authorization, Instagram will redirected the user to the URL in
C<redirect_uri> with a code as an URL query parameter. This code is needed
to obtain an acess token.
$instagram->code( $code );
my $access_token = $instagram->get_access_token;
=head3 Request
With the access token its possible to do Instagram API requests using the
authenticated user credentials.
$instagram->access_token( $access_token );
my $me = $instagram->user;
print $me->full_name;
=head1 METHODS
=head2 new
my $instagram = API::Instagram->new({
client_id => $client_id,
client_secret => $client_secret,
redirect_uri => 'http://localhost',
scope => 'basic',
lib/API/Instagram.pm view on Meta::CPAN
C<scope> is the scope of access. See L<http://instagram.com/developer/authentication/#scope>.
C<response_type> and C<granty_type> do no vary. See L<http://instagram.com/developer/authentication/>.
By default, L<API::Instagram> caches created objects to avoid duplications. You can disable
this feature setting a true value to C<no_chace> parameter.
=head2 instance
my $instagram = API::Instagram->instance;
print $instagram->user->full_name;
or
my $instagram = API::Instagram->instance({
client_id => $client_id,
client_secret => $client_secret,
redirect_uri => 'http://localhost',
});
Returns the singleton instance of L<API::Instagram>.
Note: if no instance was created before, creates a new L<API::Instagram> object initialized with arguments provided and then returns it.
=head2 get_auth_url
my $auth_url = $instagram->get_auth_url;
print $auth_url;
Returns an Instagram authorization URL.
=head2 get_access_token
my $access_token = $instagram->get_access_token;
or
my ( $access_token, $auth_user ) = $instagram->get_access_token;
lib/API/Instagram.pm view on Meta::CPAN
Returns an L<API::Instagram::Search> object, capable to search for the given B<type>.
Where B<type> can be: C<user>, C<media>, C<tag> or C<location>.
See L<API::Instagram::Search> for more details and examples.
=head2 popular_medias
my $medias = $user->popular_medias( count => 3 );
print $_->caption . $/ for @$medias;
Returns a list of L<API::Instagram::Media> objects of Instagram most popular media at the moment.
=head1 AUTHOR
Gabriel Vieira <gabriel.vieira@gmail.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Gabriel Vieira.
lib/API/Instagram/Location.pm view on Meta::CPAN
has longitude => ( is => 'lazy' );
has name => ( is => 'lazy' );
has _data => ( is => 'rwp', lazy => 1, builder => 1, clearer => 1 );
sub recent_medias {
my $self = shift;
carp "Not available for location with no ID." and return [] unless $self->has_id;
my $url = sprintf "locations/%s/media/recent", $self->id;
API::Instagram->instance->_medias( $url, { @_%2?():@_ } );
}
sub _build_name { shift->_data->{name} }
sub _build_latitude { shift->_data->{latitude} }
sub _build_longitude { shift->_data->{longitude} }
sub _build__data {
my $self = shift;
carp "Not available for location with no ID." and return {} unless $self->has_id;
my $url = sprintf "locations/%s", $self->id;
API::Instagram->instance->_get( $url );
}
1;
__END__
=pod
=encoding UTF-8
lib/API/Instagram/Location.pm view on Meta::CPAN
API::Instagram::Location - Instagram Location Object
=head1 VERSION
version 0.013
=head1 SYNOPSIS
my $location = $instagram->location(123);
printf "Media Location: %s (%f,%f)", $location->name, $location->latitude, $location->longitude;
for my $media ( @{ $location->recent_medias( count => 5) } ) {
printf "Caption: %s\n", $media->caption;
printf "Posted by %s (%d likes)\n\n", $media->user->username, $media->likes;
}
=head1 DESCRIPTION
See L<http://instagr.am/developer/endpoints/locations/>.
=head1 ATTRIBUTES
=head2 id
lib/API/Instagram/Location.pm view on Meta::CPAN
=head2 longitude
Returns the longitude of the location.
=head1 METHODS
=head2 recent_medias
my $medias = $location->recent_medias( count => 5 );
print $_->caption . $/ for @$medias;
Returns a list of L<API::Instagram::Media> objects of recent medias from the location.
Accepts C<count>, C<min_timestamp>, C<min_id>, C<max_id> and C<max_timestamp> as parameters.
=head1 AUTHOR
Gabriel Vieira <gabriel.vieira@gmail.com>
=head1 COPYRIGHT AND LICENSE
lib/API/Instagram/Media.pm view on Meta::CPAN
sub last_likes {
my $self = shift;
$self->_clear_data if shift;
my $api = $self->_api;
[ map { $api->user($_) } @{ $self->_data->{likes}->{data} } ]
}
sub get_likes {
my $self = shift;
my %opts = @_;
my $url = sprintf "media/%s/likes", $self->id;
my $api = $self->_api;
[ map { $api->user($_) } $api->_get_list( { %opts, url => $url } ) ]
}
sub like {
my $self = shift;
my $url = sprintf "media/%s/likes", $self->id;
$self->_api->_post( $url )
}
sub dislike {
my $self = shift;
my $url = sprintf "media/%s/likes", $self->id;
$self->_api->_del( $url )
}
sub comments {
my $self = shift;
$self->_clear_data if shift;
$self->_data->{comments}->{count}
}
sub last_comments {
my $self = shift;
$self->_clear_data if shift;
my $api = $self->_api;
[ map { $api->_comment( { %$_, media => $self } ) } @{ $self->_data->{comments}->{data} } ]
}
sub get_comments {
my $self = shift;
my %opts = @_;
my $url = sprintf "media/%s/comments", $self->id;
my $api = $self->_api;
[ map { $api->_comment( { %$_, media => $self } ) } $api->_get_list( { %opts, url => $url } ) ]
}
sub comment {
my $self = shift;
my $text = shift;
my $url = sprintf "media/%s/comments", $self->id;
$self->_api->_post( $url, { text => $text } )
}
sub _build__api { API::Instagram->instance }
sub _build_user { shift->_data->{user} }
sub _build_tags { shift->_data->{tags} }
sub _build_location { shift->_data->{location} }
sub _build_users_in_photo { shift->_data->{users_in_photo} }
sub _build_type { shift->_data->{type} }
sub _build_link { shift->_data->{link} }
sub _build_filter { shift->_data->{filter} }
sub _build_images { shift->_data->{images} }
sub _build_videos { shift->_data->{videos} }
sub _build_caption { shift->_data->{caption } }
sub _build_created_time { shift->_data->{created_time} }
sub _build__data {
my $self = shift;
my $url = sprintf "media/%s", $self->id;
$self->_api->_get( $url );
}
############################################################
# Attributes coercion that API::Instagram object reference #
############################################################
sub _coerce_user { API::Instagram->instance->user ( $_[0] ) };
sub _coerce_location { API::Instagram->instance->location( $_[0] ) if $_[0] };
sub _coerce_tags {
lib/API/Instagram/Media.pm view on Meta::CPAN
API::Instagram::Media - Instagram Media Object
=head1 VERSION
version 0.013
=head1 SYNOPSIS
my $media = $instagram->media(3);
printf "Caption: %s\n", $media->caption;
printf "Posted by %s (%d likes)\n\n", $media->user->username, $media->likes;
my $location = $media->location;
printf "Media Location: %s (%f,%f)", $location->name, $location->latitude, $location->longitude;
=head1 DESCRIPTION
See L<http://instagr.am/developer/endpoints/media/>.
=head1 ATTRIBUTES
=head2 id
Returns media id.
lib/API/Instagram/Media.pm view on Meta::CPAN
Returns a list L<API::Instagram::Tag> objects of media tags.
=head2 location
Returns media L<API::Instagram::Location> object.
=head2 images
my $thumbnail = $media->images->{thumbnail};
printf "URL: %s (%d x %d)" $thumbnail->{url}, $thumbnail->{width}, $thumbnail->{height};
Returns media images options and details.
=head2 videos
my $standart = $media->videos->{standart_resolution};
printf "URL: %s (%d x %d)" $standart->{url}, $standart->{width}, $standart->{height};
Returns media videos options and details, when video type.
=head2 users_in_photo
for my $each ( @{ $media->users_in_photo } ) {
my $user = $each->{user};
my $position = $each->{position};
printf "%s is at %f, %f\n", $user->username, $position->{x}, $position->{y};
}
Returns a list of L<API::Instagram::User> objects of users tagged in the media with their coordinates.
=head2 caption
Returns media caption text.
=head2 created_time
Returns the media date in a L<Time::Moment> object.
=head1 METHODS
=head2 likes
printf "Total Likes: %d\n", $media->likes; # Total likes when object was created
or
printf "Total Likes: %d\n", $media->likes(1); # Up to date total likes
Returns media total likes.
If you set C<1> as parameter it will renew all media data and return an up-do-date total likes.
Note: C<1> as parameter also updates total comments, last likes and last comments.
=head2 last_likes
for my $user ( @{ $media->last_likes } ) {
say $user->username;
lib/API/Instagram/Media.pm view on Meta::CPAN
Sets a like on the media by the authenticated user.
=head2 dislike
$media->dislike;
Removes a like on the media by the authenticated user.
=head2 comments
printf "Total Comments: %d\n", $media->comments; # Total comments when object was created
or
printf "Total Comments: %d\n", $media->comments(1); # Up to date total comments
Returns media total comments.
If you set C<1> as parameter it will renew all media data and return an up-do-date total comments.
Note: C<1> as parameter also updates total likes, last likes and last comments.
=head2 last_comments
for my $comment ( @{ $media->last_comments } ) {
printf "%s: %s\n", $comment->from->username, $comment->text;
}
Returns a list of C<API::Instagram::Media::Comment> of the last comments on the media.
If you set C<1> as parameter it will renew all media data and return an up-do-date list.
Note: C<1> as parameter also updates total likes, total comments and last likes.
=head2 get_comments
my @comments = $media->get_comments( count => 5 );
lib/API/Instagram/Media/Comment.pm view on Meta::CPAN
use Time::Moment;
has id => ( is => 'ro', required => 1 );
has from => ( is => 'ro', required => 1, coerce => sub { API::Instagram->instance->user( $_[0] ) } );
has text => ( is => 'ro', required => 1 );
has media => ( is => 'ro', required => 1 );
has created_time => ( is => 'ro', coerce => sub { Time::Moment->from_epoch( $_[0] ) } );
sub remove {
my $self = shift;
my $url = sprintf "media/%s/comments/%s", $self->media->id, $self->id;
$self->media->_api->_del( $url )
}
1;
__END__
=pod
=encoding UTF-8
lib/API/Instagram/Media/Comment.pm view on Meta::CPAN
=head1 NAME
API::Instagram::Media::Comment - Instagram Media Comment Object
=head1 VERSION
version 0.013
=head1 SYNOPSIS
print $comment->text . "\n-\n";
print "By %s, at year %d\n", $comment->from->full_name, $comment->created_time->year;
=head1 DESCRIPTION
See L<http://instagr.am/developer/endpoints/comments/>.
=head1 ATTRIBUTES
=head2 id
Returns comment id.
lib/API/Instagram/Tag.pm view on Meta::CPAN
sub media_count {
my $self = shift;
$self->_clear_data if shift;
$self->_data->{media_count}
}
sub recent_medias {
my $self = shift;
my $url = sprintf "tags/%s/media/recent", $self->name;
API::Instagram->instance->_medias( $url, { @_%2?():@_ } );
}
sub _build__data {
my $self = shift;
my $url = sprintf "tags/%s", $self->name;
API::Instagram->instance->_get( $url );
}
1;
__END__
=pod
=encoding UTF-8
lib/API/Instagram/Tag.pm view on Meta::CPAN
API::Instagram::Tag - Instagram Tag Object
=head1 VERSION
version 0.013
=head1 SYNOPSIS
my $tag = $instagram->tag('perl');
printf "Count: %s", $tag->media_count;
for my $media ( @{ $tag->recent_medias( count => 5) } ) {
printf "Caption: %s\n", $media->caption;
printf "Posted by %s (%d likes)\n\n", $media->user->username, $media->likes;
}
=head1 DESCRIPTION
See L<http://instagr.am/developer/endpoints/tags/>.
=head1 ATTRIBUTES
=head2 name
lib/API/Instagram/Tag.pm view on Meta::CPAN
=head2 media_count
Returns the total media tagged with it.
=head1 METHODS
=head2 recent_medias
my $medias = $tag->recent_medias( count => 5 );
print $_->caption . $/ for @m$edias;
Returns a list of L<API::Instagram::Media> objects of recent medias tagged with it.
Accepts C<count>, C<min_timestamp>, C<min_id>, C<max_id> and C<max_timestamp> as parameters.
=head1 AUTHOR
Gabriel Vieira <gabriel.vieira@gmail.com>
=head1 COPYRIGHT AND LICENSE
lib/API/Instagram/User.pm view on Meta::CPAN
}
sub get_followers {
shift->_get_relashions( @_, relationship => 'followed-by' );
}
sub recent_medias {
my $self = shift;
my $url = sprintf "users/%s/media/recent", $self->id;
$self->_api->_medias( $url, { @_%2?():@_ }, { token_not_required => 1 } );
}
sub relationship {
my $self = shift;
my $action = shift;
my $url = sprintf "users/%s/relationship", $self->id;
my @actions = qw/ follow unfollow block unblock approve ignore/;
use experimental 'smartmatch';
if ( $action ) {
if ( $action ~~ @actions ){
return $self->_api->_post( $url, { action => $action } )
}
carp "Invalid action";
}
$self->_api->_get( $url );
}
sub _get_relashions {
my $self = shift;
my %opts = @_;
my $url = sprintf "users/%s/%s", $self->id, $opts{relationship};
my $api = $self->_api;
[ map { $api->user($_) } $api->_get_list( { %opts, url => $url } ) ]
}
sub _self_requests {
my ($self, $type, $url, %opts) = @_;
if ( $self->id ne $self->_api->user->id ){
carp "The $type is only available for the authenticated user";
return;
lib/API/Instagram/User.pm view on Meta::CPAN
sub _build__api { API::Instagram->instance }
sub _build_username { shift->_data->{username} }
sub _build_full_name { shift->_data->{full_name} }
sub _build_bio { shift->_data->{bio} }
sub _build_website { shift->_data->{website} }
sub _build_profile_picture { shift->_data->{profile_picture} }
sub _build__data {
my $self = shift;
my $url = sprintf "users/%s", $self->id;
$self->_api->_get( $url );
}
1;
__END__
=pod
lib/API/Instagram/User.pm view on Meta::CPAN
=head1 VERSION
version 0.013
=head1 SYNOPSIS
my $me = $instagram->user;
my $other = $instagra->user(12345);
printf "My username is %s and I follow %d other users.\n", $me->username, $me->follows;
printf "The other user full name is %s", $other->full_name;
=head1 DESCRIPTION
See L<http://instagr.am/developer/endpoints/users/> and L<http://instagram.com/developer/endpoints/relationships/>.
=head1 ATTRIBUTES
=head2 id
Returns user id.
lib/API/Instagram/User.pm view on Meta::CPAN
=head2 followed_by
Returns user total followers.
=head1 METHODS
=head2 feed
my $medias = $user->feed( count => 5 );
print $_->caption . $/ for @$medias;
Returns a list of L<API::Instagram::Media> objects of the authenticated user feed.
Accepts C<count>, C<min_id> and C<max_id> as parameters.
=head2 liked_media
my $medias = $user->liked_media( count => 5 );
print $_->caption . $/ for @$medias;
Returns a list of L<API::Instagram::Media> objects of medias liked by the authenticated user.
Accepts C<count> and C<max_like_id> as parameters.
=head2 requested_by
my $requested_by = $user->get_requested_by( count => 5 );
print $_->username . $/ for @$requested_by;
Returns a list of L<API::Instagram::User> objects of users who requested this user's permission to follow.
Accepts C<count> as parameter.
=head2 get_follows
my $follows = $user->get_follows( count => 5 );
print $_->username . $/ for @$follows;
Returns a list of L<API::Instagram::User> objects of users this user follows.
Accepts C<count> as parameter.
=head2 get_followers
my $followers = $user->get_followers( count => 5 );
print $_->username . $/ for @$followers;
Returns a list of L<API::Instagram::User> objects of users this user is followed by.
Accepts C<count> as parameter.
=head2 recent_medias
my $medias = $user->recent_medias( count => 5 );
print $_->caption . $/ for @$medias;
Returns a list of L<API::Instagram::Media> objects of user's recent medias.
Accepts C<count>, C<min_timestamp>, C<min_id>, C<max_id> and C<max_timestamp> as parameters.
=head2 relationship
my $relationship = $user->relationship;
say $relationship->{incoming_status};