繁体   English   中英

facebook graph API的响应错误

[英]Error in the response from facebook graph API

到目前为止,我的代码是这样的:

<script>
    window.fbAsyncInit = function(){
        FB.init({ appId:'my app id', status:true,  cookie:true, xfbml:true});

        FB.getLoginStatus(function(response){
            if (response.status != "unknown") // makes sure the user is already logged in.
            {
                FB.api('/me', function(response) {
                console.log(response);
                });
            }
        });
    };
    // Load the SDK Asynchronously
    (function(d){
        var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        d.getElementsByTagName('head')[0].appendChild(js);
    }(document));
</script>

我在控制台中遇到的错误是"An active access token must be used to query information about the current user." 但是我已经确保从代码中看到用户已登录,那么我在哪里出错呢?

更新:从答案和评论来看,问题似乎是尽管用户已登录,但我的网站未获得授权。我只想在网站上显示用户的真实姓名并显示欢迎消息。 我可以为此使用facebook graph API吗? 我不想进入授权步骤,因为从用户的角度来看这似乎是不必要的。

我是编程,JavaScript和Facebook图形api的新手,所以请原谅我可能犯的任何错误。

您在哪里确保用户已登录? 您没有在任何地方授权该用户,仅检查该用户是否已登录。例如:

FB.login(function(response) {
    if (response.authResponse) {
        //user just authorized your app

    }
}, {scope: 'email,public_profile'});

您可能也想正确使用getLoginStatus:

FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
        //user is authorized

    } else {
        //user is not authorized

    }
});

来源: http//www.devils-heaven.com/facebook-javascript-sdk-login/

暂无
暂无

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

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