简体   繁体   English

facebook graph API的响应错误

[英]Error in the response from facebook graph API

My code till now is this: 到目前为止,我的代码是这样的:

<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>

The error that I'm getting in the console is "An active access token must be used to query information about the current user." 我在控制台中遇到的错误是"An active access token must be used to query information about the current user." But I have already made sure that the user is logged in as seen from the code, then where am I making a mistake? 但是我已经确保从代码中看到用户已登录,那么我在哪里出错呢?

Update: From the answers and the comments, it seems like the problem is that my website is not authorized although the user is logged in. I just want to display the user's real name on the website with a welcome message. 更新:从答案和评论来看,问题似乎是尽管用户已登录,但我的网站未获得授权。我只想在网站上显示用户的真实姓名并显示欢迎消息。 Can I use facebook graph API for this? 我可以为此使用facebook graph API吗? I do not want to go into authorization step since that would seem unnecessary from the user's point of view. 我不想进入授权步骤,因为从用户的角度来看这似乎是不必要的。

I'm new to programming, javascript and facebook graph api, so please forgive any mistakes I might have made. 我是编程,JavaScript和Facebook图形api的新手,所以请原谅我可能犯的任何错误。

Where did you make sure the user is logged in? 您在哪里确保用户已登录? You did not authorize the user anywhere, you only checked if he is logged in. For example: 您没有在任何地方授权该用户,仅检查该用户是否已登录。例如:

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

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

You may want to use getLoginStatus correctly too: 您可能也想正确使用getLoginStatus:

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

    } else {
        //user is not authorized

    }
});

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

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

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