source: perl/modules/Facebook/lib/Facebook/Graph/Session.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.1 KB
Line 
1package Facebook::Graph::Session;
2BEGIN {
3  $Facebook::Graph::Session::VERSION = '1.0300';
4}
5
6use Any::Moose;
7use Facebook::Graph::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 sessions => (
22    is      => 'ro',
23    required=> 1,
24);
25
26sub 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
39sub 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}
50
51no Any::Moose;
52__PACKAGE__->meta->make_immutable;
53
54
55=head1 NAME
56
57Facebook::Graph::Session - Convert old API sessions into Graph API access_tokens.
58
59
60=head1 VERSION
61
62version 1.0300
63
64=head1 SYNOPSIS
65
66 my $fb = Facebook::Graph->new(
67    secret      => $facebook_application_secret,
68    app_id      => $facebook_application_id,
69    postback    => 'https://www.yourapplication.com/facebook/postback',
70 );
71 my $tokens = $fb->session(\@session_ids)->request->as_hashref;
72
73=head1 DESCRIPTION
74
75Allows you to request convert your old sessions into access tokens.
76
77B<NOTE:> If you're writing your application from scratch using L<Facebook::Graph> then you'll never need this module.
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::Response> object. Example JSON response:
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.