来自facebook图形API的响应错误 [英] Error in the response from facebook graph API

查看:106
本文介绍了来自facebook图形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." But I have already made sure that the user is logged in as seen from the code, then where am I making a mistake?

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

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? I do not want to go into authorization step since that would seem unnecessary from the user's point of view.

我是新来的编程,javascript和Facebook图api,所以请原谅我可能做的任何错误。

I'm new to programming, javascript and facebook graph api, so please forgive any mistakes I might have made.

推荐答案

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

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

您可能还想正确使用getLoginStatus:

You may want to use getLoginStatus correctly too:

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/

这篇关于来自facebook图形API的响应错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆