source: perl/modules/Facebook/lib/Facebook/Graph/AccessToken.pm @ 2a42248

release-1.9
Last change on this file since 2a42248 was 2a42248, checked in by Edward Z. Yang <ezyang@mit.edu>, 11 years ago
Add vanilla Facebook::Graph. Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
  • Property mode set to 100644
File size: 2.1 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 LWP::UserAgent;
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) = @_;
46    my $response = LWP::UserAgent->new->get($self->uri_as_string);
47    return Facebook::Graph::AccessToken::Response->new(response => $response);
48}
49
50no Any::Moose;
51__PACKAGE__->meta->make_immutable;
52
53
54=head1 NAME
55
56Facebook::Graph::AccessToken - Acquire an access token from Facebook.
57
58
59=head1 VERSION
60
61version 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
77Allows 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
83Returns the URI that will be called to fetch the token as a string. Mostly useful for debugging and testing.
84
85=head2 request ()
86
87Makes a request to Facebook to fetch an access token. Returns a L<Facebook::Graph::AccessToken::Response> object.
88
89=head1 LEGAL
90
91Facebook::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
Note: See TracBrowser for help on using the repository browser.