Graph.pm

filter: Statementstmt 46.8% 89 / 190 Branchbran 6.2% 4 / 64 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 59.5% 25 / 42 Podpod 100% 21 / 21 totaltotal 42.5% 139 / 327 CC 35 SCAR 23.2
CC
35
Cov
36%
add_page_tab
30.0
request_extended_access_token
20.0
add_post
20.0
CRAP 10.2
« Graph/BatchRequests.pm ↑ Summary Graph/Publish/Link.pm »
1 package Facebook::Graph;
2 4 $Facebook::Graph::VERSION = '1.1101';
3 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use MIME::Base64::URLSafe;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Facebook::Graph::AccessToken;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Facebook::Graph::Authorize;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Facebook::Graph::Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Facebook::Graph::Picture;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Facebook::Graph::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Facebook::Graph::Publish::Post;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Facebook::Graph::Publish::Photo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Facebook::Graph::Publish::Checkin;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Facebook::Graph::Publish::Like;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use Facebook::Graph::Publish::Comment;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Facebook::Graph::Publish::Link;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Facebook::Graph::Publish::RSVPMaybe;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use Facebook::Graph::Publish::RSVPAttending;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use Facebook::Graph::Publish::RSVPDeclined;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use Facebook::Graph::Publish::PageTab;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use Facebook::Graph::BatchRequests;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶use Facebook::Graph::Page::Feed;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶use Ouch;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 4 has app_id => (
26 is => 'ro',
27 );
28  
29 4 has secret => (
30 is => 'ro',
31 predicate => 'has_secret',
32 );
33  
34 4 has postback => (
35 is => 'rw',
36 );
37  
38 4 has access_token => (
39 is => 'rw',
40 predicate => 'has_access_token',
41 );
42  
43 sub parse_signed_request {
44 1 ▶ my ($self, $signed_request) = @_;
Subroutine parse_signed_request: called CC=3 SCAR=11.5
Pod documented
45 1 require Digest::SHA;
46 1 my ($encoded_sig, $payload) = split(/\./, $signed_request);
47  
48 1 my $sig = urlsafe_b64decode($encoded_sig);
49 1 my $data = JSON->new->decode(urlsafe_b64decode($payload));
50  
51 1 ▶ if (uc($data->{'algorithm'}) ne "HMAC-SHA256") {
Branch: 1 branch
BranchTrueFalseTotal
if (uc $data->{"algorithm"} ne "HMAC-SHA256") 0 1 1
52 0 ouch '500', 'Unknown algorithm. Expected HMAC-SHA256';
53 }
54  
55 1 my $expected_sig = Digest::SHA::hmac_sha256($payload, $self->secret);
56 1 ▶ if ($sig ne $expected_sig) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sig ne $expected_sig) 0 1 1
57 0 ouch '500', 'Bad Signed JSON signature!';
58 }
59 1 return $data;
60 }
61  
62 sub request_access_token {
63 2 ▶ my ($self, $code) = @_;
Subroutine request_access_token: called CC=1 SCAR=0.0
Pod documented
64 2 my $token = Facebook::Graph::AccessToken->new(
65 code => $code,
66 postback => $self->postback,
67 secret => $self->secret,
68 app_id => $self->app_id,
69 )->request;
70 2 $self->access_token($token->token);
71 2 return $token;
72 }
73  
74 sub request_extended_access_token {
75 0 ▶ my ($self, $access_token) = @_;
Subroutine request_extended_access_token: not called CC=4 SCAR=30.0
Pod documented
76  
77 0 ▶ die "request_extended_access_token requires an access_token" unless $access_token or $self->has_access_token;
Branch: 1 branch
BranchTrueFalseTotal
unless $access_token or $self->has_access_token 0 0 0
Condition0%0/3
$access_token or $self->has_access_token
l!l&&r!l&&!r
000
MC/DC0%0/2
$access_token or $self->has_access_token
$access_token $self->has_access_token
Truth table0%0/3
A or B
A= $access_tokenB= $self->has_access_token
ABresult
1X1
011
000
78 0 ▶ $access_token = $access_token ? $access_token : $self->access_token;
Branch: 1 branch
BranchTrueFalseTotal
$access_token ? : 0 0 0
79  
80 0 my $token = Facebook::Graph::AccessToken->new(
81 access_token => $access_token,
82 postback => $self->postback,
83 secret => $self->secret,
84 app_id => $self->app_id,
85 )->request;
86 0 $self->access_token($token->token);
87 0 return $token;
88 }
89  
90 sub convert_sessions {
91 0 ▶ my ($self, $sessions) = @_;
Subroutine convert_sessions: not called CC=1 SCAR=6.9
Pod documented
92 0 return Facebook::Graph::Session->new(
93 secret => $self->secret,
94 app_id => $self->app_id,
95 sessions => $sessions,
96 )
97 ->request
98 ->as_hashref;
99 }
100  
101 sub authorize {
102 0 ▶ my ($self) = @_;
Subroutine authorize: not called CC=1 SCAR=6.9
Pod documented
103 0 return Facebook::Graph::Authorize->new(
104 app_id => $self->app_id,
105 postback => $self->postback,
106 );
107 }
108  
109 sub fetch {
110 0 ▶ my ($self, $object_name, %params) = @_;
Subroutine fetch: not called CC=1 SCAR=6.9
Pod documented
111 0 return $self->query->find($object_name, %params)->request->as_hashref;
112 }
113  
114 sub request {
115 0 ▶ my ($self, $uri) = @_;
Subroutine request: not called CC=1 SCAR=6.9
Pod documented
116 0 return Facebook::Graph::Request->new->get($uri);
117 }
118  
119 sub query {
120 1 ▶ my ($self, %params) = @_;
Subroutine query: called CC=3 SCAR=12.7
Pod documented
121 1 ▶ if ($self->has_access_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_access_token) 0 1 1
122 0 $params{access_token} = $self->access_token;
123 }
124 1 ▶ if ($self->has_secret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_secret) 0 1 1
125 0 $params{secret} = $self->secret;
126 }
127 1 return Facebook::Graph::Query->new(%params);
128 }
129  
130 sub batch_requests {
131 0 ▶ my ($self, %params) = @_;
Subroutine batch_requests: not called CC=1 SCAR=6.9
Pod documented
132 0 $params{access_token} = $self->access_token;
133 0 return Facebook::Graph::BatchRequests->new(%params);
134 }
135  
136 sub picture {
137 1 ▶ my ($self, $object_name, %params) = @_;
Subroutine picture: called CC=1 SCAR=0.0
Pod documented
138 1 $params{object_name} = $object_name;
139 1 return Facebook::Graph::Picture->new( %params );
140 }
141  
142 sub add_post {
143 0 ▶ my ($self, $object_name, %params) = @_;
Subroutine add_post: not called CC=4 SCAR=30.0
Pod documented
144 0 ▶ if ($object_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object_name) 0 0 0
145 0 $params{object_name} = $object_name;
146 }
147 0 ▶ if ($self->has_access_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_access_token) 0 0 0
148 0 $params{access_token} = $self->access_token;
149 }
150 0 ▶ if ($self->has_secret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_secret) 0 0 0
151 0 $params{secret} = $self->secret;
152 }
153 0 return Facebook::Graph::Publish::Post->new( %params );
154 }
155  
156  
157 sub add_page_feed {
158 0 ▶ my ($self, %params) = @_;
Subroutine add_page_feed: not called CC=3 SCAR=24.8
Pod documented
159 0 ▶ if ($self->has_access_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_access_token) 0 0 0
160 0 $params{access_token} = $self->access_token;
161 }
162 0 ▶ if ($self->has_secret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_secret) 0 0 0
163 0 $params{secret} = $self->secret;
164 }
165 0 return Facebook::Graph::Page::Feed->new( %params );
166 };
167  
168  
169 sub add_photo {
170 0 ▶ my ($self, $object_name, %params) = @_;
Subroutine add_photo: not called CC=4 SCAR=30.0
Pod documented
171 0 ▶ if ($object_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object_name) 0 0 0
172 0 $params{object_name} = $object_name;
173 }
174 0 ▶ if ($self->has_access_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_access_token) 0 0 0
175 0 $params{access_token} = $self->access_token;
176 }
177 0 ▶ if ($self->has_secret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_secret) 0 0 0
178 0 $params{secret} = $self->secret;
179 }
180 0 return Facebook::Graph::Publish::Photo->new( %params );
181 }
182  
183 sub add_checkin {
184 0 ▶ my ($self, $object_name, %params) = @_;
Subroutine add_checkin: not called CC=4 SCAR=30.0
Pod documented
185 0 ▶ if ($object_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object_name) 0 0 0
186 0 $params{object_name} = $object_name;
187 }
188 0 ▶ if ($self->has_access_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_access_token) 0 0 0
189 0 $params{access_token} = $self->access_token;
190 }
191 0 ▶ if ($self->has_secret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_secret) 0 0 0
192 0 $params{secret} = $self->secret;
193 }
194 0 return Facebook::Graph::Publish::Checkin->new( %params );
195 }
196  
197 sub add_like {
198 0 ▶ my ($self, $object_name, %params) = @_;
Subroutine add_like: not called CC=3 SCAR=24.8
Pod documented
199 0 $params{object_name} = $object_name;
200 0 ▶ if ($self->has_access_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_access_token) 0 0 0
201 0 $params{access_token} = $self->access_token;
202 }
203 0 ▶ if ($self->has_secret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_secret) 0 0 0
204 0 $params{secret} = $self->secret;
205 }
206 0 return Facebook::Graph::Publish::Like->new( %params );
207 }
208  
209 sub add_comment {
210 0 ▶ my ($self, $object_name, %params) = @_;
Subroutine add_comment: not called CC=3 SCAR=24.8
Pod documented
211 0 $params{object_name} = $object_name;
212 0 ▶ if ($self->has_access_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_access_token) 0 0 0
213 0 $params{access_token} = $self->access_token;
214 }
215 0 ▶ if ($self->has_secret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_secret) 0 0 0
216 0 $params{secret} = $self->secret;
217 }
218 0 return Facebook::Graph::Publish::Comment->new( %params );
219 }
220  
221 sub add_link {
222 0 ▶ my ($self, %params) = @_;
Subroutine add_link: not called CC=3 SCAR=24.8
Pod documented
223 0 ▶ if ($self->has_access_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_access_token) 0 0 0
224 0 $params{access_token} = $self->access_token;
225 }
226 0 ▶ if ($self->has_secret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_secret) 0 0 0
227 0 $params{secret} = $self->secret;
228 }
229 0 return Facebook::Graph::Publish::Link->new( %params );
230 }
231  
232 sub add_page_tab {
233 0 ▶ my ($self, $object_name, $app_id, %params) = @_;
Subroutine add_page_tab: not called CC=5 SCAR=34.0
Pod documented
234  
235 0 ▶ die "page_id and app_id are required" unless $object_name and $app_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $object_name and $app_id 0 0 0
Condition0%0/3
$object_name and $app_id
!ll&&!rl&&r
000
MC/DC0%0/2
$object_name and $app_id
$object_name $app_id
Truth table0%0/3
A and B
A= $object_nameB= $app_id
ABresult
0X0
100
111
236  
237 0 $params{object_name} = $object_name;
238  
239 0 ▶ if ($self->has_access_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_access_token) 0 0 0
240 0 $params{access_token} = $self->access_token;
241 }
242  
243 0 ▶ if ($self->has_secret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_secret) 0 0 0
244 0 $params{secret} = $self->secret;
245 }
246  
247 0 $params{app_id} = $app_id;
248  
249 0 return Facebook::Graph::Publish::PageTab->new( %params );
250 }
251  
252  
253  
254 sub rsvp_maybe {
255 0 ▶ my ($self, $object_name, %params) = @_;
Subroutine rsvp_maybe: not called CC=3 SCAR=24.8
Pod documented
256 0 $params{object_name} = $object_name;
257 0 ▶ if ($self->has_access_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_access_token) 0 0 0
258 0 $params{access_token} = $self->access_token;
259 }
260 0 ▶ if ($self->has_secret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_secret) 0 0 0
261 0 $params{secret} = $self->secret;
262 }
263 0 return Facebook::Graph::Publish::RSVPMaybe->new( %params );
264 }
265  
266 sub rsvp_attending {
267 0 ▶ my ($self, $object_name, %params) = @_;
Subroutine rsvp_attending: not called CC=3 SCAR=24.8
Pod documented
268 0 $params{object_name} = $object_name;
269 0 ▶ if ($self->has_access_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_access_token) 0 0 0
270 0 $params{access_token} = $self->access_token;
271 }
272 0 ▶ if ($self->has_secret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_secret) 0 0 0
273 0 $params{secret} = $self->secret;
274 }
275 0 return Facebook::Graph::Publish::RSVPAttending->new( %params );
276 }
277  
278 sub rsvp_declined {
279 0 ▶ my ($self, $object_name, %params) = @_;
Subroutine rsvp_declined: not called CC=3 SCAR=24.8
Pod documented
280 0 $params{object_name} = $object_name;
281 0 ▶ if ($self->has_access_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_access_token) 0 0 0
282 0 $params{access_token} = $self->access_token;
283 }
284 0 ▶ if ($self->has_secret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_secret) 0 0 0
285 0 $params{secret} = $self->secret;
286 }
287 0 return Facebook::Graph::Publish::RSVPDeclined->new( %params );
288 }
289  
290  
291 4 1;
292  
293 =head1 NAME
294  
295 Facebook::Graph - A fast and easy way to integrate your apps with Facebook.
296  
297 =head1 VERSION
298  
299 version 1.1101
300  
301 =head1 SYNOPSIS
302  
303 my $fb = Facebook::Graph->new;
304 $fb->access_token($token);
305 my $sarah_bownds = $fb->fetch('767598108');
306 my $perl_page = $fb->fetch('16665510298');
307  
308 Or better yet:
309  
310 my $sarah_bownds = $fb->query
311 ->find('767598108')
312 ->include_metadata
313 ->select_fields(qw( id name picture ))
314 ->request
315 ->as_hashref;
316  
317 my $sarahs_picture_uri = $fb->picture('sarahbownds')->get_large->uri_as_string;
318  
319 You can also do asynchronous calls like this:
320  
321 my $sarah = $fb->query->find('767598108'); # making request in background here
322 # ... do stuff here ...
323 my $hashref = $sarah->as_hashref; # handling the response here
324  
325  
326 Or fetching a response from a URI you already have:
327  
328 my $hashref = $fb->request('https://graph.facebook.com/16665510298')->as_hashref;
329  
330  
331 =head2 Building A Privileged App
332  
333 my $fb = Facebook::Graph->new(
334 app_id => $facebook_application_id,
335 secret => $facebook_application_secret,
336 postback => 'https://www.yourapplication.com/facebook/oauth/postback',
337 );
338  
339 Get the user to authorize your app (only needed if you want to fetch non-public information or publish stuff):
340  
341 my $uri = $fb
342 ->authorize
343 ->extend_permissions(qw(offline_access publish_stream))
344 ->uri_as_string;
345  
346 # redirect the user's browser to $uri
347  
348 Handle the Facebook authorization code postback:
349  
350 my $q = Plack::Request->new($env);
351 $fb->request_access_token($q->query_param('code'));
352  
353 #now retrieve extended access token
354 $fb->request_extended_access_token; #extended access token now in $fb->access_token
355  
356 Or if you already had the access token:
357  
358 $fb->access_token($token);
359 $fb->request_extended_access_token;
360  
361 Or simply:
362  
363 $fb->request_extended_access_token($token);
364  
365 Get some info:
366  
367 my $user = $fb->fetch('me');
368 my $friends = $fb->fetch('me/friends');
369 my $perl_page = $fb->fetch('16665510298');
370  
371 Use a different version of the API:
372  
373 my $user = $fb->fetch('me', api_version => 'v2.5');
374  
375 =head1 DESCRIPTION
376  
377 This is a Perl interface to the Facebook Graph API L<http://developers.facebook.com/docs/api>. With this module you can currently query public Facebook data, query privileged Facebook data, and build a privileged Facebook application. See the TODO for all that this module cannot yet do.
378  
379 For example code, see L<Facebook::Graph::Cookbook>.
380  
381 B<WARNING:> The work on this module has only just begun because the Graph API itself isn't very new, and I'm only working on it as I have some tuits. Therefore things are potentially subject to change drastically with each release.
382  
383  
384 =head1 METHODS
385  
386 =head2 new ( [ params ] )
387  
388 The constructor.
389  
390 =head3 params
391  
392 A hash of base parameters, just so you don't have to pass them around. If you only want to do public queries then these params are not needed.
393  
394 =over
395  
396 =item access_token
397  
398 An access token string used to make Facebook requests as a privileged user. Required if you want to make privileged queries or perform privileged actions on Facebook objects.
399  
400 =item app_id
401  
402 The application id that you get from Facebook after registering (L<http://developers.facebook.com/setup/>) your application on their site. Required if you'll be calling the C<request_access_token>, C<convert_sessions>, or C<authorize> methods.
403  
404 =item secret
405  
406 The application secret that you get from Facebook after registering your application. Required if you'll be calling the C<request_access_token> or C<convert_sessions> methods.
407  
408 =item postback
409  
410 The URI that Facebook should post your authorization code back to. Required if you'll be calling the C<request_access_token> or C<authorize> methods.
411  
412 B<NOTE:> It must be a sub URI of the URI that you put in the Application Settings > Connect > Connect URL field of your application's profile on Facebook.
413  
414 =back
415  
416  
417 =head2 authorize ( )
418  
419 Creates a L<Facebook::Graph::Authorize> object, which can be used to get permissions from a user for your application.
420  
421  
422 =head2 request_access_token ( code )
423  
424 Creates a L<Facebook::Graph::AccessToken> object and fetches an access token from Facebook, which will allow everything you do with Facebook::Graph to work within user privileges rather than through the public interface. Returns a L<Facebook::Graph::AccessToken::Response> object, and also sets the C<access_token> property in the Facebook::Graph object.
425  
426 =head2 request_extended_access_token ( access_token )
427  
428 Note: access_token is optional. Creates a L<Facebook::Graph::AccessToken> object and fetches an (https://developers.facebook.com/docs/facebook-login/access-tokens/#extending) extended access token from Facebook.
429 This method accepts an optional access token. If you have called C<request_access_token> already on the Facebook::Graph object and C<access_token> is set, then you do not have to pass
430 in an access token. However, if you have an access token stored from a previous object, you will need to pass it in.
431  
432 =head3 code
433  
434 An authorization code string that you should have gotten by going through the C<authorize> process.
435  
436  
437 =head2 query ( )
438  
439 Creates a L<Facebook::Graph::Query> object, which can be used to fetch and search data from Facebook.
440  
441 =head2 batch_requests ( uri )
442  
443 Creates a L<Facebook::Graph::BatchRequests> object, which can be used to send multiple requests in a single HTTP request.
444  
445 =head2 request ( uri )
446  
447 Fetch a Facebook::Graph URI you already have.
448  
449 =head3 uri
450  
451 The URI to fetch. For example: https://graph.facebook.com/amazon
452  
453 =head2 fetch ( id )
454  
455 Returns a hash reference of an object from facebook. A quick way to grab an object from Facebook. These two statements are identical:
456  
457 my $sarah = $fb->fetch('767598108');
458  
459 my $sarah = $fb->query->find('767598108')->request->as_hashref;
460  
461 =head3 id
462  
463 An object id like C<16665510298> for the Perl page.
464  
465 =head2 picture ( id )
466  
467 Returns a L<Facebook::Graph::Picture> object, which can be used to generate the URLs of the pictures of any object on Facebook.
468  
469 =head3 id
470  
471 An object id like C<16665510298> for the Perl page.
472  
473  
474  
475 =head2 add_post ( [ id ] )
476  
477 Creates a L<Facebook::Graph::Publish::Post> object, which can be used to publish data to a user's feed/wall.
478  
479 =head2 add_page_feed ( )
480  
481 Creates a L<Facebook::Graph::Page::Feed> object, which can be used to add a post to a Facebook page.
482  
483 =head2 add_photo ( [ id ] )
484  
485 Creates a L<Facebook::Graph::Publish::Photo> object, which can be used to publish a photo to a user's feed/wall.
486  
487 =head3 id
488  
489 Optionally provide an object id to place it on. Requires that you have administrative access to that page/object.
490  
491  
492 =head2 add_checkin ( [ id ] )
493  
494 Creates a L<Facebook::Graph::Publish::Checkin> object, which can be used to publish a checkin to a location.
495  
496 =head3 id
497  
498 Optionally provide an user id to check in. Requires that you have administrative access to that user.
499  
500  
501 =head2 add_like ( id )
502  
503 Creates a L<Facebook::Graph::Publish::Like> object to tell everyone about a post you like.
504  
505 =head3 id
506  
507 The id of a post you like.
508  
509  
510 =head2 add_comment ( id )
511  
512 Creates a L<Facebook::Graph::Publish::Comment> object that you can use to comment on a note.
513  
514 =head3 id
515  
516 The id of the post you want to comment on.
517  
518  
519 =head2 add_link ( )
520  
521 Creates a L<Facebook::Graph::Publish::Link> object, which can be used to publish links.
522  
523  
524 =head2 add_page_tab ( page_id, app_id )
525  
526 Creates a L<Facebook::Graph::Publish::PageTab> object, which can be used to publish an app as a page tab.
527  
528 =head3 id
529  
530 Optionally provide an object id to place it on. Requires that you have administrative access to that page/object.
531  
532  
533  
534 =head2 rsvp_maybe ( id )
535  
536 RSVP as 'maybe' to an event.
537  
538 =head3 id
539  
540 The id of an event.
541  
542 =head2 rsvp_attending ( id )
543  
544 RSVP as 'attending' to an event.
545  
546 =head3 id
547  
548 The id of an event.
549  
550 =head2 rsvp_declined ( id )
551  
552 RSVP as 'declined' to an event.
553  
554 =head3 id
555  
556 The id of an event.
557  
558  
559  
560 =head2 convert_sessions ( sessions )
561  
562 A utility method to convert old sessions into access tokens that can be used with the Graph API. Returns an array reference of hash references of access tokens.
563  
564 [
565 {
566 "access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
567 "expires": 1271649600,
568 },
569 ...
570 ]
571  
572 See also L<Facebook::Graph::Session>.
573  
574 =head3 sessions
575  
576 An array reference of session ids from the old Facebook API.
577  
578  
579 =head2 parse_signed_request ( $signed_request )
580  
581 Allows the decoding of signed requests for canvas applications to ensure data passed back from Facebook isn't tampered with. You can read more about this at L<http://developers.facebook.com/docs/authentication/canvas>.
582  
583 =head3 $signed_request
584  
585 A signature string passed from Facebook. To capture a signed request your app must be displayed within the Facebook canvas page and then you must pull the query parameter called C<signed_request> from the query string.
586  
587 B<NOTE:> To get this passed to your app you must enable it in your migration settings for your app (L<http://www.facebook.com/developers/>).
588  
589 =head1 EXCEPTIONS
590  
591 This module throws exceptions when it encounters a problem. It uses L<Ouch> to throw the exception, and the Exception typically takes 3 parts: code, message, and a data portion that is the URI that was originally requested. For example:
592  
593 eval { $fb->call_some_method };
594 if (kiss 500) {
595 say "error: ". $@->message;
596 say "uri: ".$@->data;
597 }
598 else {
599 throw $@; # rethrow the error
600 }
601  
602 =head1 CAVEATS
603  
604 The Facebook Graph API is a constantly moving target. As such some stuff that used to work, may stop working. Keep up to date with their changes here: L<https://developers.facebook.com/docs/apps/upgrading>
605  
606 If you were using any version of Facebook::Graph before 1.1000, then you may be used to doing things like creating events through this API, or using a person's username instead of their ID, or making queries without an access token. You can't do any of those things anymore, because as of the Facebook Graph v2.0 API, none of them is supported any longer.
607  
608  
609 =head1 PREREQS
610  
611 L<Moo>
612 L<JSON>
613 L<LWP::UserAgent>
614 L<LWP::Protocol::https>
615 L<URI>
616 L<DateTime>
617 L<DateTime::Format::Strptime>
618 L<MIME::Base64::URLSafe>
619 L<Ouch>
620  
621 =head2 Optional
622  
623 L<Digest::SHA> is used for signed requests. If you don't plan on using the signed request feature, then you do not need to install Digest::SHA.
624  
625 =head1 SUPPORT
626  
627 =over
628  
629 =item Repository
630  
631 L<http://github.com/rizen/Facebook-Graph>
632  
633 =item Bug Reports
634  
635 L<http://github.com/rizen/Facebook-Graph/issues>
636  
637 =back
638  
639  
640 =head1 SEE ALSO
641  
642 I highly recommend L<Facebook::OpenGraph>. I may even switch to it myself soon.
643  
644  
645 =head1 AUTHOR
646  
647 JT Smith <jt_at_plainblack_dot_com>
648  
649 =head1 LEGAL
650  
651 Facebook::Graph is Copyright 2010 - 2012 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself.
652  
653 =cut
« Graph/BatchRequests.pm ↑ Summary Graph/Publish/Link.pm »