简体   繁体   English

hello.js,获取访问令牌(或所有其他内容)

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

I'm trying to use hello.js to allow users to login using their social media accounts. 我正在尝试使用hello.js允许用户使用其社交媒体帐户登录。 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. 这样可以正常工作,我在Facebook应用程序中看到该应用程序已连接。 I've tried to follow the instructions here in order to show the object after login but I see nothing with console.log(token) . 我尝试按照此处的说明进行操作,以便在登录后显示对象,但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. 我需要看一些有用的东西。

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. userDetails包含用户凭据。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM