File: flickr_method_test_login.pl

package info (click to toggle)
libflickr-api-perl 1.29-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 464 kB
  • sloc: perl: 1,471; makefile: 22
file content (141 lines) | stat: -rw-r--r-- 3,053 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/perl
#
# Method Test Login
#

=pod

=head1 NAME

flickr_method_test_echo.pl

a login example for using either OAuth or Old School Flickr

=cut

use warnings;
use strict;
use Flickr::API;
use Getopt::Long;


=pod

=head1 DESCRIPTION

This script uses either the Flickr or OAuth parameters to call
the flickr.test.login method.

=head1 USAGE

  flickr_method_test_login.pl --use_api=[oauth, flickr] \
    --key="24680beef13579feed987654321ddcc6" \
    --secret="de0cafe4feed0242" \
    --token="72157beefcafe3582-1ad0feedface0e60" \
   [--token_secret="33beef1face212d"]

Depending on what you specify with B<--use_api> the flickr.test.login
call will use the appropriate parameter set. The B<--token_secret> is
used by OAuth, but not by the original Flickr.


=cut

my $config = {};
my $api;

my %args;

GetOptions(
    $config,
    'use_api=s',
    'key=s',
    'secret=s',
    'token=s',
    'token_secret=s',
);


=head1 CALL DIFFERENCES

    if ($config->{use_api} =~ m/flickr/i) {
        $api = Flickr::API->new({
            'key'        => $config->{key},
            'secret'     => $config->{secret},
            'auth_token' => $config->{token},
        });

        $args{'api_key'}    = $config->{key};
        $args{'auth_token'} = $config->{token};
    }
    elsif ($config->{use_api} =~ m/oauth/i) {
        $api = Flickr::API->new({
            'consumer_key'    => $config->{key},
            'consumer_secret' => $config->{secret},
            'token'           => $config->{token},
            'token_secret'    => $config->{token_secret},
        });

        $args{'consumer_key'} = $config->{key};
        $args{'token'} = $config->{token};
    }
    else {
        die "\n --use_api must be either 'flickr' or 'oauth' \n";
    }

=cut

if ($config->{use_api} && $config->{use_api} eq 'flickr') {
    $api = Flickr::API->new({
        'key'        => $config->{key},
        'secret'     => $config->{secret},
        'auth_token' => $config->{token},
    });

    $args{'api_key'}    = $config->{key};
    $args{'auth_token'} = $config->{token};
}
elsif ($config->{use_api} && $config->{use_api} eq 'oauth') {
    $api = Flickr::API->new({
        'consumer_key'    => $config->{key},
        'consumer_secret' => $config->{secret},
        'token'           => $config->{token},
        'token_secret'    => $config->{token_secret},
    });

    $args{'consumer_key'} = $config->{key};
    $args{'token'} = $config->{token};
}
else {
    die "\n --use_api must be either 'flickr' or 'oauth'\n";
}


my $response = $api->execute_method('flickr.test.login', \%args);

my $ref = $response->as_hash();

if ($api->is_oauth) {
    print "\nOAuth formated login status: ",$ref->{stat},"\n";
}
else {
    print "\nFlickr formated login status: ",$ref->{stat},"\n";
}

exit;

__END__

=pod

=head1 AUTHOR

Louis B. Moore <lbmoore at cpan.org>  Based on the code in Flickr::API.

=head1 LICENSE AND COPYRIGHT

Copyright 2014, Louis B. Moore

This program is released under the Artistic License 2.0 by The Perl Foundation.

=cut