source: perl/modules/Facebook/lib/Facebook/Graph/Session.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.0 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 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 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) = @_;
41    my $response = LWP::UserAgent->new->get($self->uri_as_string);
42    return Facebook::Graph::Response->new(response => $response);
43}
44
45no Any::Moose;
46__PACKAGE__->meta->make_immutable;
47
48
49=head1 NAME
50
51Facebook::Graph::Session - Convert old API sessions into Graph API access_tokens.
52
53
54=head1 VERSION
55
56version 1.0300
57
58=head1 SYNOPSIS
59
60 my $fb = Facebook::Graph->new(
61    secret      => $facebook_application_secret,
62    app_id      => $facebook_application_id,
63    postback    => 'https://www.yourapplication.com/facebook/postback',
64 );
65 my $tokens = $fb->session(\@session_ids)->request->as_hashref;
66
67=head1 DESCRIPTION
68
69Allows you to request convert your old sessions into access tokens.
70
71B<NOTE:> If you're writing your application from scratch using L<Facebook::Graph> then you'll never need this module.
72
73=head1 METHODS
74
75=head2 uri_as_string ()
76
77Returns the URI that will be called to fetch the token as a string. Mostly useful for debugging and testing.
78
79=head2 request ()
80
81Makes a request to Facebook to fetch an access token. Returns a L<Facebook::Graph::Response> object. Example JSON response:
82
83=head1 LEGAL
84
85Facebook::Graph is Copyright 2010 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself.
86
87=cut
Note: See TracBrowser for help on using the repository browser.