hello.js, get access token (or anything at all)

1.7k views Asked by At

I'm trying to use hello.js to allow users to login using their social media accounts. I seem to be successfully getting the allow page to show, and a redirect is happening but I don't understand how my system is supposed to know who that person is. I'm assuming it's via the access token but I can't seem to print it to the console at any point of the login process.

$('#facebookLogin').on('click', function(e){
    e.preventDefault();
    hello('facebook').login({display:'page'});
    return false;
});

This "works" as in, I see the app connected in my Facebook apps. I've tried to follow the instructions here in order to show the object after login but I see nothing with console.log(token).

$('#facebookLogin').on('click', function(e){
    e.preventDefault();
    hello( 'facebook' ).login({display: 'page'} function() {
       var token = hello( 'facebook' ).getAuthResponse().access_token;
       console.log(token);
    });
    return false;
});

I humbly request that if you have answer to post working code. There's a lot of text trying to explain this and I really don't understand it. I need to see something that works.

1

There are 1 answers

0
Alberto I.N.J. On

Try this code.

$('#facebookLogin').on('click', function(event) {
    event.preventDefault();

    hello('facebook').login({display: 'page'},
    function() {
        hello('facebook').api("me")
                .then(function(userDetails) {
                    console.log("hello api success");
                    console.log(userDetails);
                }, function(e) {
                    console.log(e);
                });
    });

    return false;

});

userDetails contains user credentials.

Hope it helps.