Flickr::API(3pm)
π¦ Flickr::API β the Flickr::API(3pm) page, bestie edition π
User Contributed Perl Documentation Β· Flickr::API(3pm)
okay so. you wanna talk to Flickr from Perl. this is the module for that. pull up a chair, grab a boba, we're doing this together π§β¨
β¨ NAME β¨
Flickr::API β the Perl interface to the Flickr API. that's it, that's the whole name, and honestly? iconic. π
πΈ SYNOPSIS πΈ
π Using OAuth to call a method not requiring authentication
no auth needed for this one, we're just vibing with OAuth:
use Flickr::API;
my $api = Flickr::API->new({
'consumer_key' => 'your_api_key',
'consumer_secret' => 'your_app_secret',
});
my $response = $api->execute_method('flickr.test.echo', {
'foo' => 'bar',
'baz' => 'quux',
});
my $config_file = $HOME/saved-flickr.st;
$api->export_storable_config($config_file);
see how we just execute_method and then save the config with export_storable_config? chef's kiss. π«Ά
π Non-OAuth method calling method not requiring authentication
the old-school route. heads up tho:
use Flickr::API;
# key deprecated in favor of api_key
# secret deprecated in favor of api_secret
#
my $api = Flickr::API->new({
'api_key' => 'your_api_key',
'api_secret' => 'your_app_secret',
});
my $response = $api->execute_method('flickr.test.echo', {
'foo' => 'bar',
'baz' => 'quux',
});
lowkey important:keyis deprecated in favor ofapi_key, andsecretis deprecated in favor ofapi_secret. the comments literally say so, and we respect the comments. π
π Alternatively, Using OAuth for non-authenticated request
okay so this version is a little more β¨formalβ¨ β you build an actual Flickr::API::Request object first:
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);
note the execute_request($request) instead of execute_method(...). different function, same energy. π₯
π Authenticate an OAuth API Object starting with saved configuration
this is the whole glow-up arc: load your saved config, get a request token, send your bestie (the user) to a browser, get the token back, trade it for an access token, save, party.
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();
}
the way this works is: oauth_request_token gives you $rt_rc, and if it comes back eq 'ok' you get the authorize URI with oauth_authorize_uri ('perms' => 'read' here), paste it in a browser, and then feed the redirect URL back into the prompt so we can split out the token. then oauth_access_token takes \%request_token, and if that returns eq 'ok' we export_storable_config($config_file) and go call flickr.auth.oauth.checkToken (grab it as as_hash()) and flickr.prefs.getPrivacy (grab it as as_tree()). two different response shapes, both valid. π
π The OAuth authorization uri will look something like:
https://api.flickr.com/services/oauth/authorize?oauth_token=12345678901234567-890abcdefedcba98&perms=read
π The callback is called with a token and verifier such as:
https://127.0.0.1/?oauth_token=12345678901234567-890abcdefedcba98&oauth_verifier=cafe12345678feed
π« DESCRIPTION π«
so basically: an interface for using the Flickr API. that's the mission statement, we're keeping it simple. π
and here's the fun part β Flickr::API is a subclass of LWP::UserAgent, which means all of the various proxy, request limits, caching, etc are available. you inherit the whole toolbox, no cap. π§°
Flickr::API can instantiate using either the Flickr Authentication (which is deprecated, bestie β she's retired π) or the OAuth Authentication. and OAuth is handled using Net::OAuth. periodt. π
π SUBROUTINES/METHODS π
π new({ opt => 'value', ... }) π
okay so this is the constructor, right? you feed it a hash of options and it blesses you with a brand new Flickr::API object. the options go a little something like this:
- either
api_keyfor the Flickr auth orconsumer_keyfor OAuth β that's your API key, bestie. one form or the other is required, no skipping π - either
api_secretfor the Flickr auth orconsumer_secretfor OAuth β your API key's secret. the one that matches whichever ofapi_key/consumer_keyyou picked is required. rest_uri&auth_uriβ override the URIs used for contacting the API. you know, if you're feeling custom β¨lwpobjβ base theFlickr::APIon this object instead of making a whole new instance of LWP::UserAgent. super handy when you wanna use the features of, like, LWP::UserAgent::Cached. iconic behaviour tbh.unicodeβ this flag decides whetherFlickr::APIexpects you to hand it UTF-8 bytes (unicode=0, which is the default) or actual unicode strings (unicode=1) in the request. pick your fighter πnonce,timestamp,request_method,signature_method,request_urlβ Net::OAuth uses these to assemble and sign the OAuth consumer request Flickr API calls. the defaults are usually fine, don't stress π«Άcallbackβ the callback is used in oauth authentication. when Flickr authorizes you, it hands back the access token and access token secret in a callback URL. this defaults tohttps://127.0.0.1/tokenandtoken_secretβ Net::OAuth uses these to assemble and sign the OAuth protected resource request Flickr API calls.
π¦ execute_method($method, $args) π¦
it builds a Flickr::API::Request object, runs it, and gives you back a Flickr::API::Response object. that's the whole vibe. β¨
π¦ execute_request($request) π¦
runs a Flickr::API::Request object and returns a Flickr::API::Response object. and listen β calls get signed if you specified a secret when you created the Flickr::API object. no secret, no signature, iykyk.
π¦ request_auth_url($perms,$frob) π¦
returns a URI object for the URL your app has to redirect a user to so they can approve an authentication token.
$perms must be read, write, or delete.
for web-based applications, $frob is an optional parameter.
it returns undef if a secret wasn't specified when you made the Flickr::API object. π
π¦ export_config([$type,$params]) π¦
returns a hash of all β or part β of the persistent bits of the Flickr::API object, with some extra behaviours baked in for Flickr::API objects using OAuth.
- oauth message type: one of
Consumer,Protected Resource,Request Token,Authorize UserorAccess Tokenβ this is one of the message types that Net::OAuth handles. message type is optional. - oauth parameter set:
messageorAPIor undef. β Net::OAuth will return message params, api params, or all params, depending on what you asked for. all params is the default.
if the Flickr::API object identifies as Flickr original authentication, you get back a hashref:
$VAR1 = {
'frob' => '12332112332112300-feedabcde123456c-1234567',
'api_key' => 'cafefeedbeef13579246801234567890',
'api_secret' => 'beef321432154321',
'token' => '97531086421234567-cafe123456789abc'
};
or the subset thereof, depending on what the API has actually used. and if the older form of key/secret was used, the constructor changes those into the api_key/api_secret forms. glow-up π
if the API object identifies as OAuth authentication and message type is specified, then export_config returns a hash of the OAuth parameters for the specified Net::OAuth message type. and further β if parameter is specified, then export_config returns either the set of message parameters or api parameters for the message type. if parameter is not specified, then both parameter types come back. for example:
my %config = $api->export_config('protected resource');
or
my %config = $api->export_config('protected resource','message');
when export_config is called with no arguments, it returns the OAuth portion of the Flickr::API object. and if they're present, the Net::OAuth Request Token and Access Token objects are included too. π
VAR1 = {
'access_token' => bless( {
'extra_params' => {
'fullname' => 'Louis',
'user_nsid' => '12345678@N00',
'username' => 'meanameicallmyself'
},
'from_hash' => 1,
'token' => '12345678901234567-cafe123098765432',
'token_secret' => 'eebeef000fedbca1'
}, 'Net::OAuth::AccessTokenResponse' ),
'callback' => 'https://127.0.0.1',
'consumer_key' => 'cafefeedbeef13579246801234567890',
'consumer_secret' => 'fedcba9876543210',
'nonce' => '917fa882fa7babd5a1b7702e7d19502a',
'request_method' => 'GET',
'request_url' => 'https://api.flickr.com/services/rest/',
'signature_method' => 'HMAC-SHA1',
'timestamp' => 1436129308,
'token' => '12345678901234567-cafe123098765432',
'token_secret' => 'eebeef000fedbca1',
'version' => '1.0'
};
my %config = $api->export_config();
you can use this method to extract and save the API parameters for future use. future you says thank you. π«Ά
π¦ export_storable_config(filename) π¦
this one wraps export_config with a file open and a storable store_fd, which adds some persistence to a Flickr::API object. lowkey the easiest glow-up for your config.
π¦ import_storable_config(filename) π¦
this method grabs a storable config of a Flickr::API object and revivifies the object. it's giving resurrection, main character energy. π₯
π¦ get_oauth_request_type() π¦
returns the oauth request type sitting in the Flickr::API object. heads up: some Flickr methods need a protected resource request type and others just want a simple consumer request type. pick correctly or it's a vibe check fail π
π¦ oauth_request_token(\%args) π¦
assembles, signs, and makes the OAuth Request Token call β and if it succeeds, it stores the Net::OAuth Request Token right in the Flickr::API object. slay.
the required parameters are:
consumer_keyβ your API Keyconsumer_secretβ your API Key's secretrequest_methodβ the URI Method:GETorPOSTrequest_urlβ defaults to:<https://api.flickr.com/services/oauth/request_token>flickr_access_tokenβ (listed in the source docs, exactly like this)
and then, also straight from the source docs:
keyβ the required parameters are:
ok bestie, that last little fragment is in the original docs just like that, so we're keeping it just like that. no cap, nothing invented, nothing removed. π
π¦ oauth_access_token(\%args) π¦
assembles, signs, and makes the OAuth Access Token call β and if it works out, it stores the Net::OAuth Access Token in the Flickr::API object. β¨
the required parameters are:
consumer_keyβ your API Keyconsumer_secretβ your API Key's secretrequest_methodβ the URI Method:GETorPOSTrequest_urlβ defaults to:<https://api.flickr.com/services/oauth/access_token>token_secretβ the request token secret from the Net::OAuth Request Token object that came back from theoauth_request_tokencall.
π¦ oauth_authorize_uri(\%args) π¦
returns a URI object for the URL your app has to redirect a user to so they can approve a request token.
permsβ the permission the application is requesting, one ofread,write, ordelete, and it defaults toread.
π¦ is_oauth π¦
returns 1 if the Flickr::API object is OAuth flavored, 0 otherwise. simple as that, bestie. π
π AUTHOR π
Cal Henderson, <cal@iamcal.com>
Auth API patches provided by Aaron Straup Cope
Subclassing patch from AHP
OAuth patches and additions Louis B. Moore <lbmoore@cpan.org>
π LICENSE AND COPYRIGHT π
Copyright (C) 2004-2013, Cal Henderson, <cal@iamcal.com>
OAuth patches and additions Copyright (C) 2014-2016 Louis B. Moore <lbmoore@cpan.org>
This program is released under the Artistic License 2.0 by The Perl Foundation.
π SEE ALSO π
Flickr::API::RequestFlickr::API::ResponseNet::OAuthXML::Parser::LiteFlickr<http://www.flickr.com/><http://www.flickr.com/services/api/><https://www.flickr.com/services/api/auth.oauth.html><https://github.com/iamcal/perl-Flickr-API>
and that's the whole page, bestie!! this was Flickr::API(3pm) as shipped with perl v5.40.1, dated 2025-05-04. go forth and make API calls, you gorgeous nerd. π¦πβ¨
π¦ where this page comes from
- debian trixie: libflickr-api-perl 1.29-2 Β· Artistic-2.0
- ubuntu resolute: libflickr-api-perl 1.29-2 Β· Artistic-2.0
- ubuntu stonking: libflickr-api-perl 1.29-2 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms