【问题标题】:facebook FB.Event.subscribe('auth.authResponseChange') not workingfacebook FB.Event.subscribe('auth.authResponseChange') 不工作
【发布时间】:2012-07-27 06:30:39
【问题描述】:

对于我的生活,我无法让 Event.subscribe('auth.authResponseChange') 工作。见下面的代码

  <div id="fb-root">
    </div>
    <script>
        window.fbAsyncInit = function () {
            FB.init({
                appId: 'XXXXXXXXXXXXXXX', // App ID
                channelUrl: 'http://XXXXXXXX.us/', // Channel File
                status: true, // check login status
                cookie: true, // enable cookies to allow the server to access the session
                xfbml: true  // parse XFBML
            });

            FB.Event.subscribe('auth.authResponseChange', function (response) {
                alert('The status of the session is: ' + response.status);
            });
        };


        // Load the SDK Asynchronously
        (function (d) {
            var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
            if (d.getElementById(id)) { return; }
            js = d.createElement('script'); js.id = id; js.async = true;
            js.src = "//connect.facebook.net/en_US/all.js";
            ref.parentNode.insertBefore(js, ref);
        } (document));
    </script>
    <div class="fb-login-button" data-size="xlarge" scope="email" data-show-faces="false"
        data-width="400" data-max-rows="1" autologoutlink="true">
        Login with Facebook</div>

登录按钮呈现。我也可以注销。唯一的问题是 auth.response 更改没有触发,我没有收到“消息”弹出窗口

【问题讨论】:

  • FBML 将很快被弃用。最好不要使用它。
  • @InspiredJW FBML 已被弃用,这是 XFBML,不会被弃用。
  • 你试过只检查response[0]吗?根据文档,请注意,在某些情况下,response 的值是无键的,但是当返回多个变量时,它包含相应的键。 => developers.facebook.com/docs/reference/javascript/…

标签: javascript html facebook


【解决方案1】:

您的代码看起来不错。

我会访问您的 Facebook 应用并特别检查 2 个设置。

  1. 检查“沙盒模式”-确保将其设置为“禁用”
  2. 检查您的站点 URL 和/或画布 URL - 确保将它们设置为您的域。 (即,如果您在本地处理此问题,您的 url 应该类似于 http://localhost:#####/ 其中 ##### 是您的端口。

希望对您有所帮助。

【讨论】:

  • 嘿,你知道如何找到我的端口号吗?
  • 如果您在 Visual Studio 中工作,请在解决方案资源管理器中右键单击您的 Web 项目,然后单击属性。在您的左侧,向下 3 层,选择 Web。在“服务器”部分选择“特定端口”并使用默认端口或选择新端口。
【解决方案2】:

您的 fbAsyncInit 函数是异步调用的,因此您不会看到任何警报消息。改用 console.log 进行调试。

【讨论】:

    猜你喜欢
    • 2012-10-02
    • 1970-01-01
    • 2011-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多