Flickr-API
view release on metacpan or search on metacpan
lib/Flickr/API.pm view on Meta::CPAN
use Flickr::API;
use Flickr::API::Request;
my $api = Flickr::API->new({'consumer_key' => 'your_api_key','consumer_secret' => 'your_app_secret'});
my $request = Flickr::API::Request->new({
'method' => 'flickr.test.echo',
'args' => {},
});
my $response = $api->execute_request($request);
=head2 Authenticate an OAuth API Object starting with saved configuration
use Flickr::API;
use Term::ReadLine;
my $config_file = "$ENV{HOME}/saved-flickr.st";
my $term = Term::ReadLine->new('Testing Flickr::API');
$term->ornaments(0);
my $api = Flickr::API->import_storable_config($config_file);
my $rt_rc = $api->oauth_request_token( { 'callback' => 'https://127.0.0.1/' } );
my %request_token;
if ( $rt_rc eq 'ok' ) {
my $uri = $api->oauth_authorize_uri({ 'perms' => 'read' });
my $prompt = "\n\n$uri\n\n" .
"Copy the above url to a browser, and authenticate with Flickr\n" .
"Press [ENTER] once you get the redirect: ";
my $input = $term->readline($prompt);
$prompt = "\n\nCopy the redirect URL from your browser and enter it\nHere: ";
$input = $term->readline($prompt);
chomp($input);
my ($callback_returned,$token_received) = split(/\?/,$input);
my (@parms) = split(/\&/,$token_received);
foreach my $pair (@parms) {
my ($key,$val) = split(/=/,$pair);
$key =~ s/oauth_//;
$request_token{$key}=$val;
}
}
my $ac_rc = $api->oauth_access_token(\%request_token);
if ( $ac_rc eq 'ok' ) {
$api->export_storable_config($config_file);
my $response = $api->execute_method('flickr.auth.oauth.checkToken');
my $hash_ref = $response->as_hash();
$response = $api->execute_method('flickr.prefs.getPrivacy');
my $rsp_node = $response->as_tree();
}
=head2 The OAuth authorization uri will look something like:
https://api.flickr.com/services/oauth/authorize?oauth_token=12345678901234567-890abcdefedcba98&perms=read
=head2 The callback is called with a token and verifier such as:
https://127.0.0.1/?oauth_token=12345678901234567-890abcdefedcba98&oauth_verifier=cafe12345678feed
=head1 DESCRIPTION
An interface for using the Flickr API.
C<Flickr::API> is a subclass of L<LWP::UserAgent>, so all of the various
proxy, request limits, caching, etc are available. C<Flickr::API> can
instantiate using either the Flickr Authentication (deprecated) or the
OAuth Authentication. OAuth is handled using L<Net::OAuth>.
=head1 SUBROUTINES/METHODS
=over
=item C<new({ opt =E<gt> 'value', ... })>
Returns as new L<Flickr::API> object. The options are as follows:
=over
=item either C<api_key> for the Flickr auth or C<consumer_key> for OAuth
Your API key (one or the other form is required)
=item either C<api_secret> for the Flickr auth or C<consumer_secret> for OAuth
Your API key's secret (the one matching the api_key/consumer_key is required)
=item C<rest_uri> & C<auth_uri>
Override the URIs used for contacting the API.
=item C<lwpobj>
Base the C<Flickr::API> on this object, instead of creating a new instance of L<LWP::UserAgent>.
This is useful for using the features of e.g. L<LWP::UserAgent::Cached>.
=item C<unicode>
This flag controls whether Flickr::API expects you to pass UTF-8 bytes (unicode=0, the default) or
actual unicode strings (unicode=1) in the request.
=item C<nonce>, C<timestamp>, C<request_method>, C<signature_method>, C<request_url>
These values are used by L<Net::OAuth> to assemble and sign OAuth I<consumer> request
Flickr API calls. The defaults are usually fine.
=item C<callback>
( run in 1.372 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )