GithubHelp home page GithubHelp logo

net-facebook-oauth2's Introduction

NAME

Net::Facebook::Oauth2 - a simple Perl wrapper around Facebook OAuth 2.0 protocol

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   => [ 'name', 'email', 'profile_picture' ],
    display => 'page'
);

Now redirect the user to this $url.

Once the user authorizes your application, Facebook will send him/her back to your application, on the callback link provided above. PLEASE NOTE THAT YOU MUST PRE-AUTHORIZE YOUR CALLBACK URI ON FACEBOOK'S APP DASHBOARD.

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');

use Try::Tiny;  # or eval {}, or whatever

my ($unique_id, $access_token);
try {
    $access_token = $fb->get_access_token(code => $code); # <-- could die!

    # Facebook tokens last ~2h, but you may upgrade them to ~60d if you want:
    $access_token = $fb->get_long_lived_token( access_token => $access_token );

    my $access_data = $fb->debug_token( input => $access_token );
    if ($access_data && $access_data->{is_valid}) {
        $unique_id = $access_data->{user_id};
        # you could also check here for what scopes were granted to you
        # by inspecting $access_data->{scopes}->@*
    }
} catch {
    # handle errors here!
};

If you got so far, your user is logged! Save this access token in your database or session. As shown in the example above, Facebook also provides a unique user_id for this token so you can associate it with a particular user of your app.

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/v4.0/me'   # Facebook API URL
);

print $info->as_json;

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, or refer to the full documentation.

INSTALLATION

cpanm Net::Facebook::Oauth2

Or the old-fashioned manual way:

perl Makefile.PL
make
make test
make install

AUTHOR

Mahmoud A. Mehyar, <[email protected]>

CONTRIBUTORS

Big Thanks To

COPYRIGHT AND LICENSE

Copyright (C) 2012-2019 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.

net-facebook-oauth2's People

Contributors

comewalk avatar garu avatar mamod avatar manwar avatar oalders avatar valchonedelchev avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

net-facebook-oauth2's Issues

get_access_token not working / API changes

get_access_token is always returning "can't get access token", even if a valid token has been return.

This seems to be the reason:
"Note: From v2.3 onward this endpoint will return a proper JSON response. If your call doesn't specify a version it will default to the oldest available version."

I think the oldest available version returns JSON now, but the script still tries to parse xml and fails.

make a CPAN release after #9 is merged

Hi @mamod! Me again :)

After #9 is merged (let me know if there is anything I can do to help!), a new version must be pushed to CPAN so we can have upstream code depending on your module force your new released version, otherwise they risk not working anymore after April 30, 2015!

Thanks again for all the great work you've been doing!

Cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.