| 1 | package Facebook::Graph::Session; | ||
| 2 | $Facebook::Graph::Session::VERSION = '1.1205'; | ||
| 3 | use Moo; | ||
| 4 | use Facebook::Graph::Request; | ||
| 5 | with 'Facebook::Graph::Role::Uri'; | ||
| 6 | |||
| 7 | has app_id => ( | ||
| 8 | is => 'ro', | ||
| 9 | required=> 1, | ||
| 10 | ); | ||
| 11 | |||
| 12 | has secret => ( | ||
| 13 | is => 'ro', | ||
| 14 | required=> 1, | ||
| 15 | ); | ||
| 16 | |||
| 17 | has sessions => ( | ||
| 18 | is => 'ro', | ||
| 19 | required=> 1, | ||
| 20 | ); | ||
| 21 | |||
| 22 | sub uri_as_string { | ||
| 23 | my ($self) = @_; | ||
| 24 | my $uri = $self->uri; | ||
| 25 | $uri->path('oauth/access_token'); | ||
| 26 | $uri->query_form( | ||
| 27 | type => 'client_cred', | ||
| 28 | client_id => $self->app_id, | ||
| 29 | client_secret => $self->secret, | ||
| 30 | sessions => join(',', @{$self->sessions}) | ||
| 31 | ); | ||
| 32 | return $uri->as_string; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub request { | ||
| 36 | my ($self) = @_; | ||
| 37 | return Facebook::Graph::Request->new->get($self->uri_as_string); | ||
| 38 | } | ||
| 39 | |||
| 40 | 1; | ||
| 41 | |||
| 42 | =head1 NAME | ||
| 43 | |||
| 44 | Facebook::Graph::Session - Convert old API sessions into Graph API access_tokens. | ||
| 45 | |||
| 46 | |||
| 47 | =head1 VERSION | ||
| 48 | |||
| 49 | version 1.1205 | ||
| 50 | |||
| 51 | =head1 SYNOPSIS | ||
| 52 | |||
| 53 | my $fb = Facebook::Graph->new( | ||
| 54 | secret => $facebook_application_secret, | ||
| 55 | app_id => $facebook_application_id, | ||
| 56 | postback => 'https://www.yourapplication.com/facebook/postback', | ||
| 57 | ); | ||
| 58 | my $tokens = $fb->session(\@session_ids)->request->as_hashref; | ||
| 59 | |||
| 60 | =head1 DESCRIPTION | ||
| 61 | |||
| 62 | Allows you to request convert your old sessions into access tokens. | ||
| 63 | |||
| 64 | B<NOTE:> If you're writing your application from scratch using L<Facebook::Graph> then you'll never need this module. | ||
| 65 | |||
| 66 | =head1 METHODS | ||
| 67 | |||
| 68 | =head2 uri_as_string () | ||
| 69 | |||
| 70 | Returns the URI that will be called to fetch the token as a string. Mostly useful for debugging and testing. | ||
| 71 | |||
| 72 | =head2 request () | ||
| 73 | |||
| 74 | Makes a request to Facebook to fetch an access token. Returns a L<Facebook::Graph::Response> object. Example JSON response: | ||
| 75 | |||
| 76 | =head1 LEGAL | ||
| 77 | |||
| 78 | Facebook::Graph is Copyright 2010 - 2017 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself. | ||
| 79 | |||
| 80 | =cut |