[cfca761] | 1 | package Facebook::Graph::AccessToken; |
---|
| 2 | BEGIN { |
---|
| 3 | $Facebook::Graph::AccessToken::VERSION = '1.0300'; |
---|
| 4 | } |
---|
| 5 | |
---|
| 6 | use Any::Moose; |
---|
| 7 | use Facebook::Graph::AccessToken::Response; |
---|
| 8 | with 'Facebook::Graph::Role::Uri'; |
---|
[9820d55] | 9 | use AnyEvent::HTTP; |
---|
[cfca761] | 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 postback => ( |
---|
| 22 | is => 'ro', |
---|
| 23 | required=> 1, |
---|
| 24 | ); |
---|
| 25 | |
---|
| 26 | has code => ( |
---|
| 27 | is => 'ro', |
---|
| 28 | required=> 1, |
---|
| 29 | ); |
---|
| 30 | |
---|
| 31 | sub uri_as_string { |
---|
| 32 | my ($self) = @_; |
---|
| 33 | my $uri = $self->uri; |
---|
| 34 | $uri->path('oauth/access_token'); |
---|
| 35 | $uri->query_form( |
---|
| 36 | client_id => $self->app_id, |
---|
| 37 | client_secret => $self->secret, |
---|
| 38 | redirect_uri => $self->postback, |
---|
| 39 | code => $self->code, |
---|
| 40 | ); |
---|
| 41 | return $uri->as_string; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | sub request { |
---|
[9820d55] | 45 | my ($self, $cb) = @_; |
---|
| 46 | http_get $self->uri_as_string, sub { |
---|
| 47 | my ($response, $headers) = @_; |
---|
| 48 | $cb->(Facebook::Graph::AccessToken::Response->new( |
---|
| 49 | response => $response, |
---|
| 50 | headers => $headers, |
---|
| 51 | uri => $self->uri_as_string |
---|
| 52 | )); |
---|
| 53 | }; |
---|
[c104b43] | 54 | () # return nothing |
---|
[cfca761] | 55 | } |
---|
| 56 | |
---|
| 57 | no Any::Moose; |
---|
| 58 | __PACKAGE__->meta->make_immutable; |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | =head1 NAME |
---|
| 62 | |
---|
| 63 | Facebook::Graph::AccessToken - Acquire an access token from Facebook. |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | =head1 VERSION |
---|
| 67 | |
---|
| 68 | version 1.0300 |
---|
| 69 | |
---|
| 70 | =head1 SYNOPSIS |
---|
| 71 | |
---|
| 72 | my $fb = Facebook::Graph->new( |
---|
| 73 | secret => $facebook_application_secret, |
---|
| 74 | app_id => $facebook_application_id, |
---|
| 75 | postback => 'https://www.yourapplication.com/facebook/postback', |
---|
| 76 | ); |
---|
| 77 | my $token_response_object = $fb->request_access_token($code_from_authorize_postback); |
---|
| 78 | |
---|
| 79 | my $token_string = $token_response_object->token; |
---|
| 80 | my $token_expires_epoch = $token_response_object->expires; |
---|
| 81 | |
---|
| 82 | =head1 DESCRIPTION |
---|
| 83 | |
---|
| 84 | Allows you to request an access token from Facebook so you can make privileged requests on the Graph API. |
---|
| 85 | |
---|
| 86 | =head1 METHODS |
---|
| 87 | |
---|
| 88 | =head2 uri_as_string () |
---|
| 89 | |
---|
| 90 | Returns the URI that will be called to fetch the token as a string. Mostly useful for debugging and testing. |
---|
| 91 | |
---|
| 92 | =head2 request () |
---|
| 93 | |
---|
| 94 | Makes a request to Facebook to fetch an access token. Returns a L<Facebook::Graph::AccessToken::Response> object. |
---|
| 95 | |
---|
| 96 | =head1 LEGAL |
---|
| 97 | |
---|
| 98 | Facebook::Graph is Copyright 2010 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself. |
---|
| 99 | |
---|
[9820d55] | 100 | =cut |
---|