API-Instagram

 view release on metacpan or  search on metacpan

lib/API/Instagram.pm  view on Meta::CPAN


=head1 SYNOPSIS

	use API::Instagram;

	my $instagram = API::Instagram->new({
			client_id     => $client_id,
			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
C<client_secret>. See L<http://instagr.am/developer/register/> for details.

=head3 Authorize

Get the AUTH URL to authenticate.

	use API::Instagram;

	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',
			response_type => 'code',
			granty_type   => 'authorization_code',
			no_cache      => 1,
	});

Returns an L<API::Instagram> object.

Set C<client_id>, C<client_secret> and C<redirect_uri> with the ones registered
to your application. See L<http://instagram.com/developer/clients/manage/>.

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



( run in 1.212 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )