source: perl/modules/Facebook/lib/Facebook/Graph/AccessToken.pm @ 7777ac2

release-1.10release-1.9
Last change on this file since 7777ac2 was 7777ac2, checked in by Edward Z. Yang <ezyang@mit.edu>, 13 years ago
Convert to async (both Facebook::Graph and us.) Work items: - Documentation is all out of date - Think more carefully about error handling (right now it's delayed into the response object) - Really bad HTTP POST hack in Publish.pm. Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
  • Property mode set to 100644
File size: 2.2 KB
Line 
1package Facebook::Graph::AccessToken;
2BEGIN {
3  $Facebook::Graph::AccessToken::VERSION = '1.0300';
4}
5
6use Any::Moose;
7use Facebook::Graph::AccessToken::Response;
8with 'Facebook::Graph::Role::Uri';
9use AnyEvent::HTTP;
10
11has app_id => (
12    is      => 'ro',
13    required=> 1,
14);
15
16has secret => (
17    is      => 'ro',
18    required=> 1,
19);
20
21has postback => (
22    is      => 'ro',
23    required=> 1,
24);
25
26has code => (
27    is      => 'ro',
28    required=> 1,
29);
30
31sub 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
44sub request {
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    };
54}
55
56no Any::Moose;
57__PACKAGE__->meta->make_immutable;
58
59
60=head1 NAME
61
62Facebook::Graph::AccessToken - Acquire an access token from Facebook.
63
64
65=head1 VERSION
66
67version 1.0300
68
69=head1 SYNOPSIS
70
71 my $fb = Facebook::Graph->new(
72    secret      => $facebook_application_secret,
73    app_id      => $facebook_application_id,
74    postback    => 'https://www.yourapplication.com/facebook/postback',
75 );
76 my $token_response_object = $fb->request_access_token($code_from_authorize_postback);
77
78 my $token_string = $token_response_object->token;
79 my $token_expires_epoch = $token_response_object->expires;
80
81=head1 DESCRIPTION
82
83Allows you to request an access token from Facebook so you can make privileged requests on the Graph API.
84
85=head1 METHODS
86
87=head2 uri_as_string ()
88
89Returns the URI that will be called to fetch the token as a string. Mostly useful for debugging and testing.
90
91=head2 request ()
92
93Makes a request to Facebook to fetch an access token. Returns a L<Facebook::Graph::AccessToken::Response> object.
94
95=head1 LEGAL
96
97Facebook::Graph is Copyright 2010 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself.
98
99=cut
Note: See TracBrowser for help on using the repository browser.