| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Social::Service::Facebook; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
738
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
32
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
32
|
|
|
5
|
1
|
|
|
1
|
|
12
|
use base qw(Net::Social::Service); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
803
|
|
|
6
|
1
|
|
|
1
|
|
1304
|
use WWW::Facebook::API; |
|
|
1
|
|
|
|
|
140209
|
|
|
|
1
|
|
|
|
|
35
|
|
|
7
|
1
|
|
|
1
|
|
763
|
use Net::Social qw(:all); |
|
|
1
|
|
|
|
|
10243
|
|
|
|
1
|
|
|
|
|
166
|
|
|
8
|
1
|
|
|
1
|
|
9
|
use vars qw($VERSION); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
285
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = "0.1"; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Net::Social::Service::Facebook - a Facebook plugin for Net::Social |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 PARAMS |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
For reading Net::Social::Service::Facebook needs |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=over4 |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=item api_key |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
You need an API key from Facebook. You can read how to |
|
26
|
|
|
|
|
|
|
get one from here |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
http://developers.facebook.com/get_started.php |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=item session_secret |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
See below. |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=item session_key |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
See below. |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=back |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub params {( |
|
43
|
0
|
|
|
0
|
1
|
|
read => { |
|
44
|
|
|
|
|
|
|
"api_key" => { required => 1, |
|
45
|
|
|
|
|
|
|
description => "Your Facebook API key", |
|
46
|
|
|
|
|
|
|
}, |
|
47
|
|
|
|
|
|
|
"session_secret" => { required => 1, |
|
48
|
|
|
|
|
|
|
description => "Your Facebpook API secret", |
|
49
|
|
|
|
|
|
|
}, |
|
50
|
|
|
|
|
|
|
"session_key" => { required => 1, |
|
51
|
|
|
|
|
|
|
description => "Your Facebpook API secret", |
|
52
|
|
|
|
|
|
|
}, |
|
53
|
|
|
|
|
|
|
}, |
|
54
|
|
|
|
|
|
|
)} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 GETTING A PERMANENT FACEBOOK SESSION |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
I use this script |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#!perl -w |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
use strict; |
|
63
|
|
|
|
|
|
|
use WWW::Facebook::API; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $api_key = shift || die "You must pass an api key\n"; # get these when you sign up |
|
66
|
|
|
|
|
|
|
my $secret = shift || die "You must pass an api secret"; # as a facebook developer |
|
67
|
|
|
|
|
|
|
my $client = make_client($api_key, $secret); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Now get the auth token |
|
70
|
|
|
|
|
|
|
print "1) Go to ".$client->get_infinite_session_url."\n"; |
|
71
|
|
|
|
|
|
|
print "2) Press 'Generate' and get token\n"; |
|
72
|
|
|
|
|
|
|
print "3) Enter the token now\n"; |
|
73
|
|
|
|
|
|
|
chomp(my $token = <>); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Get a session |
|
76
|
|
|
|
|
|
|
$client->auth->get_session($token); |
|
77
|
|
|
|
|
|
|
$session_key = $client->session_key; |
|
78
|
|
|
|
|
|
|
$session_secret = $client->secret; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# And note the session key |
|
81
|
|
|
|
|
|
|
print "4) Your infinite session key is $session_key\n"; |
|
82
|
|
|
|
|
|
|
print "5) Your infinite session secret is $session_secret\n"; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Now make a new client and set the session key again to see that it works |
|
85
|
|
|
|
|
|
|
my $new_client = make_client($api_key, $session_secret); |
|
86
|
|
|
|
|
|
|
$new_client->session_key($session_key); |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# And get my friends |
|
89
|
|
|
|
|
|
|
my $friends = $new_client->users->get_info( uids => $new_client->friends->get, fields => 'name'); |
|
90
|
|
|
|
|
|
|
print join("\n", map { $_->{name} } @$friends)."\n"; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub make_client { |
|
93
|
|
|
|
|
|
|
my ($api_key, $secret) = @_; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $client = WWW::Facebook::API->new( |
|
96
|
|
|
|
|
|
|
parse => 1, |
|
97
|
|
|
|
|
|
|
throw_errors => 1, |
|
98
|
|
|
|
|
|
|
); |
|
99
|
|
|
|
|
|
|
$client->api_key($api_key); |
|
100
|
|
|
|
|
|
|
$client->secret($secret); |
|
101
|
|
|
|
|
|
|
$client->desktop(1); |
|
102
|
|
|
|
|
|
|
return $client; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 METHODS |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 friends |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Returns your friends. It defines the keys C, C and C. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub friends { |
|
114
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
115
|
0
|
0
|
|
|
|
|
return () unless $self->{_logged_in}; |
|
116
|
0
|
|
|
|
|
|
my $user = $self->{_details}->{username}; |
|
117
|
0
|
|
|
|
|
|
my $key = $self->{_details}->{api_key}; |
|
118
|
0
|
|
|
|
|
|
my $sess_key = $self->{_details}->{session_key}; |
|
119
|
0
|
|
|
|
|
|
my $sess_secret = $self->{_details}->{session_secret}; |
|
120
|
0
|
|
|
|
|
|
my $client = WWW::Facebook::API->new( |
|
121
|
|
|
|
|
|
|
desktop => 1, |
|
122
|
|
|
|
|
|
|
parse => 1, |
|
123
|
|
|
|
|
|
|
throw_errors => 1, |
|
124
|
|
|
|
|
|
|
# debug => 1, |
|
125
|
|
|
|
|
|
|
); |
|
126
|
|
|
|
|
|
|
#$secret = $sess_secret if defined $sess_secret. |
|
127
|
0
|
|
|
|
|
|
$client->api_key($key); |
|
128
|
0
|
|
|
|
|
|
$client->session_key($sess_key); |
|
129
|
0
|
|
|
|
|
|
$client->secret($sess_secret); |
|
130
|
0
|
|
|
|
|
|
$client->desktop(1); |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
my %friends; |
|
133
|
0
|
|
|
|
|
|
my $uids = $client->friends->get; |
|
134
|
|
|
|
|
|
|
# First get their details |
|
135
|
0
|
|
|
|
|
|
foreach my $friend (@{$client->users->get_info(uids=>$uids, |
|
|
0
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
fields=>[qw(name uid )]) |
|
137
|
|
|
|
|
|
|
}) |
|
138
|
|
|
|
|
|
|
{ |
|
139
|
0
|
|
|
|
|
|
$friends{$friend->{uid}} = { id => $friend->{uid}, name => $friend->{name}, type => MUTUAL }; |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
} |
|
142
|
0
|
|
|
|
|
|
return values %friends; |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 AUTHOR |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Simon Wistow |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Copyright, 2007 - Simon Wistow |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Distributed under the same terms as Perl itself |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; |