The original Flickr Authentication has been deprecated in favor of OAuth. This example script shows one way to use Flickr::API to go from having just the consumer_key and consumer_secret (or api_key and api_secret using Flickr's terminology) to an authenticated token.
./flickr_oauth_authentication.pl \ --consumer_key="24680beef13579feed987654321ddcc6" \ --consumer_secret="de0cafe4feed0242" \ [ --perms={read,write,delete} \] [ --config_out="/path/to/a/writable/config.st" ] [ --help ] [ --man ]
If not specified, perms defaults to read.
The script will produce a url for you to enter into a browser then prompt you to enter the callback url that is returned by flickr.
It then does a Data::Dumper dump of the parameter keys and values which can be recorded for future use. If you want to make it more complete, you could modify the script to format and dump the information into a config file of some type.
Following the flow laid out in https://www.flickr.com/services/api/auth.oauth.html
The script takes the consumer_key and consumer secret and creates a Flickr::API object. It then calls the oauth_request_token method with an optional callback specified.
my $api = Flickr::API->new($cli_args); $api->oauth_request_token({'callback' => 'https://127.0.0.1'});
The oauth request token is saved in the Flickr::API object.
The script now calls the oauth_authorize_uri method with the optional perms parameter. The Flickr::API returns a uri which (in this case) is cut in the terminal and pasted into a browser.
my $request2 = $api->oauth_authorize_uri({'perms' => $cli_args->{'perms'}}); print "\n\nYou now need to open: \n\n$request2\n\nin a browser.\n ";
Assuming all is well with the request token and oauth_authorize_uri Flickr will open a webpage to allow you to authenticate the application identified by the consumer_key to have the requested perms.
This is you, granting permission to the application.
Flickr returns an oauth_verifier in the callback. In this script you cut the callback from the browser and paste it into the terminal to continue on to the next step.
$response2 = $term->readline('Enter the callback redirected url: ');
The cutting and pasting is a little crude, but you only have to do it once.
The script takes the request token and the oauth_verifier and exchanges them for an access token.
my $request3 = $api->oauth_access_token(\%hash2);
Flickr will return an access token and token secret if all has gone well. These are stashed in the Flickr::API object.
How you save the access information is outside the scope of this example. However, the export_config method can be used to retrieve the oauth parameters from the Flickr::API object.
my %oconfig = $api->export_config('protected resource'); print Dumper(\%oconfig);
Louis B. Moore <lbmoore at cpan.org>
Copyright 2014,2016, Louis B. Moore
This program is released under the Artistic License 2.0 by The Perl Foundation.
To install Flickr::API, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Flickr::API
CPAN shell
perl -MCPAN -e shell install Flickr::API
For more information on module installation, please visit the detailed CPAN module installation guide.