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'; |
---|
9 | use LWP::UserAgent; |
---|
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 { |
---|
45 | my ($self) = @_; |
---|
46 | my $response = LWP::UserAgent->new->get($self->uri_as_string); |
---|
47 | return Facebook::Graph::AccessToken::Response->new(response => $response); |
---|
48 | } |
---|
49 | |
---|
50 | no Any::Moose; |
---|
51 | __PACKAGE__->meta->make_immutable; |
---|
52 | |
---|
53 | |
---|
54 | =head1 NAME |
---|
55 | |
---|
56 | Facebook::Graph::AccessToken - Acquire an access token from Facebook. |
---|
57 | |
---|
58 | |
---|
59 | =head1 VERSION |
---|
60 | |
---|
61 | version 1.0300 |
---|
62 | |
---|
63 | =head1 SYNOPSIS |
---|
64 | |
---|
65 | my $fb = Facebook::Graph->new( |
---|
66 | secret => $facebook_application_secret, |
---|
67 | app_id => $facebook_application_id, |
---|
68 | postback => 'https://www.yourapplication.com/facebook/postback', |
---|
69 | ); |
---|
70 | my $token_response_object = $fb->request_access_token($code_from_authorize_postback); |
---|
71 | |
---|
72 | my $token_string = $token_response_object->token; |
---|
73 | my $token_expires_epoch = $token_response_object->expires; |
---|
74 | |
---|
75 | =head1 DESCRIPTION |
---|
76 | |
---|
77 | Allows you to request an access token from Facebook so you can make privileged requests on the Graph API. |
---|
78 | |
---|
79 | =head1 METHODS |
---|
80 | |
---|
81 | =head2 uri_as_string () |
---|
82 | |
---|
83 | Returns the URI that will be called to fetch the token as a string. Mostly useful for debugging and testing. |
---|
84 | |
---|
85 | =head2 request () |
---|
86 | |
---|
87 | Makes a request to Facebook to fetch an access token. Returns a L<Facebook::Graph::AccessToken::Response> object. |
---|
88 | |
---|
89 | =head1 LEGAL |
---|
90 | |
---|
91 | Facebook::Graph is Copyright 2010 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself. |
---|
92 | |
---|
93 | =cut |
---|