【问题标题】:Ask user to authenticate before submitting form with Facebook Javascript SDK在使用 Facebook Javascript SDK 提交表单之前要求用户进行身份验证
【发布时间】:2012-04-03 00:47:05
【问题描述】:

我正在开发一个 Facebook 页面选项卡应用程序,用户将在其中使用 HTML5 画布在页面上绘图。当用户提交他们的绘图(基本上是一个表单)时,我需要检查用户是否已授予我的应用程序必要的权限。如果没有,弹出 Facebook 对话框,要求用户在提交表单之前通过我的应用程序进行身份验证。一旦用户通过身份验证(或者如果他们已经通过身份验证),请提交表单。

简而言之,如果用户使用 Facebook Javascript SDK 对我的应用进行了身份验证,我如何才能提交表单?

更新:

根据 Shaun 的建议,我能够使用 FB.getLoginStatus 和 FB.Login 解决这个问题。这是一个例子:

$('#submit').on('click', function() {
        FB.getLoginStatus(function(response) {
                if (response.status === 'connected') {
                    // User authenticated, submit the form
                } else if (response.status === 'not_authorized') {
                    // the user is logged in to Facebook,
                    // but has not authenticated your app
                    FB.login(function(response) {
                        // handle the response
                    }, {scope: 'email,'});
                } else {
                    // the user isn't logged in to Facebook.
                    FB.login(function(response) {
                        // handle the response
                    }, {scope: 'email,'});
                }
            });
        });

【问题讨论】:

    标签: facebook facebook-javascript-sdk


    【解决方案1】:

    简单回答一下,

    您需要确认 FB.getLoginStatus 以确定用户是否已经/尚未验证您的应用

    http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

    然后请他们到 FB.login 并在成功提交表单时或他们是否已授权提交表单

    http://developers.facebook.com/docs/reference/javascript/FB.login/

    【讨论】:

    • 感谢肖恩的回复。我之前使用过 FB.getLoginStatus 和 FB.Login,但我的应用程序的另一部分出现错误,导致它无法工作。您的建议有助于确认我的方向是正确的。我用示例代码更新了我的问题,展示了如何做到这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-18
    • 2012-12-15
    • 1970-01-01
    • 2011-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多