=head1 NAME Net::Facebook::Oauth2 - a simple Perl wrapper around Facebook OAuth v2.0 protocol =for html =head1 SYNOPSIS Somewhere in your application's login process: use Net::Facebook::Oauth2; my $fb = Net::Facebook::Oauth2->new( application_id => 'your_application_id', application_secret => 'your_application_secret', callback => 'http://yourdomain.com/facebook/callback' ); # get the authorization URL for your application my $url = $fb->get_authorization_url( scope => [ 'public_profile', 'email', 'offline_access', 'publish_stream' ], display => 'page' ); Now redirect the user to this C<$url>. Once the user authorizes your application, Facebook will send him/her back to your application, on the C link provided above. Inside that callback route, use the verifier code parameter that Facebook sends to get the access token: # param() below is a bogus function. Use whatever your web framework # provides (e.g. $c->req->param('code'), $cgi->param('code'), etc) my $code = param('code'); my $access_token = $fb->get_access_token(code => $code); If you got so far, your user is logged! Save this access token in your database or session. Later on you can use it to communicate with Facebook on behalf of this user: my $fb = Net::Facebook::Oauth2->new( access_token => $access_token ); my $info = $fb->get( 'https://graph.facebook.com/v2.2/me' # Facebook API URL ); print $info->as_json; =head1 DESCRIPTION Net::Facebook::Oauth2 gives you a way to simply access FaceBook Oauth 2.0 protocol For more information please see example folder shipped with this Module =head1 SEE ALSO For more information about Facebook Oauth 2.0 API Please Check L get/post Facebook Graph API L =head1 USAGE =head2 Cnew( %args )> Pass args as hash. C<%args> are: =over 4 =item * C Your application id as you get from facebook developers platform when you register your application =item * C Your application secret id as you get from facebook developers platform when you register your application =back =head2 C<$fb-Eget_authorization_url( %args )> Return an Authorization URL for your application, once you receive this URL redirect user there in order to authorize your application =over 4 =item * C ['offline_access','publish_stream',...] Array of Extended permissions as described by facebook Oauth2.0 API you can get more information about scope/Extended Permission from http://developers.facebook.com/docs/authentication/permissions Please note that requesting information other than C, C and C B =item * C callback URL, where facebook will send users after they authorize your application =item * C How to display Facebook Authorization page =over 4 =item * C This will display facebook authorization page as full page =item * C This option is useful if you want to popup authorization page as this option tell facebook to reduce the size of the authorization page =item * C From the name, for wab and mobile applications this option is the best facebook authorization page will fit there :) =back =back =head2 C<$fb-Eget_access_token( %args )> Returns access_token string One arg to pass =over 4 =item * C This is the verifier code that facebook send back to your callback URL once user authorize your app, you need to capture this code and pass to this method in order to get access_token Verifier code will be presented with your callback URL as code parameter as the following http://your-call-back-url.com?code=234er7y6fdgjdssgfsd... When access token is returned you need to save it in a secure place in order to use it later in your application =back =head2 C<$fb-Eget( $url,$args )> Send get request to facebook and returns response back from facebook =over 4 =item * C Facebook Graph API URL as string =item * C<$args> hashref of parameters to be sent with graph API URL if required =back The response returned can be formatted as the following =over 4 =item * C<$responseEas_json> Returns response as json object =item * C<$responseEas_hash> Returns response as perl hashref =back For more information about facebook grapg API, please check http://developers.facebook.com/docs/api =head2 C<$fb-Epost( $url,$args )> Send post request to facebook API, usually to post something =over 4 =item * C Facebook Graph API URL as string =item * C<$args> hashref of parameters to be sent with graph API URL =back For more information about facebook grapg API, please check http://developers.facebook.com/docs/api =head1 INSTALLATION cpanm Net::Facebook::Oauth2 Or the old-fashioned manual way: perl Makefile.PL make make test make install =head1 AUTHOR Mahmoud A. Mehyar, Emamod.mehyar@gmail.comE =head1 CONTRIBUTORS Big Thanks To =over 4 =item * Takatsugu Shigeta L<@comewalk|https://github.com/comewalk> =item * Breno G. de Oliveira L<@garu|https://github.com/garu> =item * squinker L<@squinker|https://github.com/squinker> =item * Valcho Nedelchev L<@valchonedelchev|https://github.com/valchonedelchev> =back =head1 COPYRIGHT AND LICENSE Copyright (C) 2012-2015 by Mahmoud A. Mehyar This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. =cut