Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Facebook JavaScript SDK登录_Javascript_Facebook_Facebook Graph Api - Fatal编程技术网

Facebook JavaScript SDK登录

Facebook JavaScript SDK登录,javascript,facebook,facebook-graph-api,Javascript,Facebook,Facebook Graph Api,这是我的密码。它可以在Facebook的JavaScript SDK测试控制台上完美运行,但不在这里: 我得到一个日志,下面的代码中有一个未定义的错误: function onStatus(response) { Log.info('onStatus', response); if (response.session) { showAccountInfo(); } else { showLoginButton(); } } FB.getLoginStatus(function(r

这是我的密码。它可以在Facebook的JavaScript SDK测试控制台上完美运行,但不在这里:


我得到一个日志,下面的代码中有一个未定义的错误:

function onStatus(response) {
Log.info('onStatus', response);
if (response.session) {
 showAccountInfo();
  } else {
  showLoginButton();
 }
 }
 FB.getLoginStatus(function(response) {
  onStatus(response); // once on page load
 FB.Event.subscribe('auth.statusChange', onStatus); // every status change
 });
您试图使用FB页面上存在的记录器,但不是您自己的记录器?

请尝试以下代码:

<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head></head>
<body>

<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
    FB.init({
        appId: '270423476307006',
        status: true,
        cookie: true,
        xfbml: true,
        oauth: true
    });

    FB.getLoginStatus(function(response) {
        onStatus(response); // once on page load
        FB.Event.subscribe('auth.statusChange', onStatus); // every status change
    });
};
(function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
}());
</script>

<h1>Login, Logout, Name and Profile Picture</h1>
<div id="account-info"></div>

<script>
/**
 * This assumes the user is logged in and renders their profile picture,
 * name and a logout link.
 */
function showAccountInfo(resp) {
    if( !resp.userID ) {
        // we shouldn't be here
        return;
    }
    FB.api(
    {
      method: 'fql.query',
      query: 'SELECT name,uid,pic_square FROM user WHERE uid='+resp.userID
    },
    function(response) {
      document.getElementById('account-info').innerHTML = (

        '<img src="' + response[0].pic_square + '"> ' +
        response[0].name +
        ' <img onclick="FB.logout()" style="cursor: pointer;"' +
            'src="https://s-static.ak.fbcdn.net/rsrc.php/z2Y31/hash/cxrz4k7j.gif">'
      );
    }
    );
}

/**
 * This assumes the user is logged out, and renders a login button.
 */
function showLoginButton() {
  document.getElementById('account-info').innerHTML = (
    '<img onclick="FB.login()" style="cursor: pointer;"' +
         'src="https://s-static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif">'
  );
}

/**
 * This will be called once on page load, and every time the status changes.
 */
function onStatus(response) {
  if (response.authResponse) {
    showAccountInfo(response.authResponse);
  } else {
    showLoginButton();
  }
}
</script>
</body>
现在让我们解释一下我们做了什么:

我们使用异步加载来确保FB.getLoginStatus只有在库成功加载时才会被触发 因为您正在将oauth设置为true,所以您需要更改代码以处理新的响应。参考此,您可能需要更改应用程序设置 基于2,可以使用response.authResponse.userID访问showAccountInfo中要使用的当前用户ID
您好:我仍然认为,从它最初指向的另一个域调用您的应用程序是一个问题。尝试在您的应用程序域www.booktrolle.in上创建pedurology.org上的相同页面,并查看结果。@如果您的嘿:D我的所有数据都在pedurology.org上,并且我的应用程序域按照您的建议更改为pedurology.org,那么前面的问题就解决了。但不是这个。感谢您的回复:Dor您可以将您的站点、应用程序设置中的域URL更改为pedurology.org,然后再试一次。@ifaour:是的,我试过了,但没用:|对不起,我真的不太懂代码。logger是Facebook在他们的测试页面中内置的一些自定义记录器。正在将调试信息写入浏览器控制台或页面上的某个隐藏div。无论哪种方式,日志记录程序都没有在您的页面上定义,因此您的脚本在有机会执行任何操作之前就会中断。取出Log.info'onStatus',响应;排队,你应该可以走了。
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head></head>
<body>

<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
    FB.init({
        appId: '270423476307006',
        status: true,
        cookie: true,
        xfbml: true,
        oauth: true
    });

    FB.getLoginStatus(function(response) {
        onStatus(response); // once on page load
        FB.Event.subscribe('auth.statusChange', onStatus); // every status change
    });
};
(function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
}());
</script>

<h1>Login, Logout, Name and Profile Picture</h1>
<div id="account-info"></div>

<script>
/**
 * This assumes the user is logged in and renders their profile picture,
 * name and a logout link.
 */
function showAccountInfo(resp) {
    if( !resp.userID ) {
        // we shouldn't be here
        return;
    }
    FB.api(
    {
      method: 'fql.query',
      query: 'SELECT name,uid,pic_square FROM user WHERE uid='+resp.userID
    },
    function(response) {
      document.getElementById('account-info').innerHTML = (

        '<img src="' + response[0].pic_square + '"> ' +
        response[0].name +
        ' <img onclick="FB.logout()" style="cursor: pointer;"' +
            'src="https://s-static.ak.fbcdn.net/rsrc.php/z2Y31/hash/cxrz4k7j.gif">'
      );
    }
    );
}

/**
 * This assumes the user is logged out, and renders a login button.
 */
function showLoginButton() {
  document.getElementById('account-info').innerHTML = (
    '<img onclick="FB.login()" style="cursor: pointer;"' +
         'src="https://s-static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif">'
  );
}

/**
 * This will be called once on page load, and every time the status changes.
 */
function onStatus(response) {
  if (response.authResponse) {
    showAccountInfo(response.authResponse);
  } else {
    showLoginButton();
  }
}
</script>
</body>