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