【问题标题】:Facebook + Prompt for publish stream onlyFacebook + 仅提示发布流
【发布时间】:2012-09-23 20:03:49
【问题描述】:

如果我有一个用户已经登录到 facebook,但从他/她的帐户中删除了我的应用程序,我如何才能在用户已经登录后再次进入我的应用程序时才提示发布_stream?

谢谢。

    FB.getLoginStatus(function (response) {
            if (response.status === 'connected') {
                // the user is logged in and has authenticated your
                // app, and response.authResponse supplies
                // the user's ID, a valid access token, a signed
                // request, and the time the access token 
                // and signed request each expire
                uid = response.authResponse.userID;
                accesstoken = response.authResponse.accessToken;
                SrReferral = '@ViewBag.Referral';
                window.fbuserid = uid;
                var postData = { facebookUID: uid, facebookAccessTok: accesstoken, facebookSrReferral: SrReferral };
                $.ajax({
                    url: '@Url.Action("DisplayGolfers")',
                    type: 'POST',
                    data: postData,
                    dataType: 'html',
                    success: function (responseText) {
                        $("#container").html(responseText);
                    }
                });
            } else if (response.status === 'not_authorized') {
                // the user is logged in to Facebook, 
                // but has not authenticated your app 
            } else {
                // the user isn't logged in to Facebook.
                window.FB.login(function (response) {
                    if (response.authResponse) {
                        uid = response.authResponse.userID;
                        accesstoken = response.authResponse.accessToken;
                        SrReferral = '@ViewBag.Referral';
                        window.fbuserid = uid;
                        var postData = { facebookUID: uid, facebookAccessTok: accesstoken, facebookSrReferral: SrReferral };
                        $.ajax({
                            url: '@Url.Action("DisplayGolfers")',
                            type: 'POST',
                            data: postData,
                            dataType: 'html',
                            success: function (responseText) {
                                $("#container").html(responseText);
                            }
                        });
                    } else {
                        console.log('User cancelled login or did not fully authorize.');
                        alert('User cancelled login');
                    }
                }, { scope: 'publish_stream' });
            };
        });
    }  

【问题讨论】:

    标签: javascript facebook


    【解决方案1】:

    似乎我误解了您的问题,您希望用户保持登录状态,即使他从 Facebook 帐户中删除了应用程序。这真的很糟糕,很容易成为安全问题。

    一旦用户删除了您的应用程序,他就不应再登录了!

    如果您不想在用户下次访问您的应用程序之前提示用户权限,您应该定义您的情况下的“下一次”(小时/天/浏览器会话/等)并设置一些 cookie/会话来检查每次访问是否是正确的提示时间。


    您可以使用FB.getLoginStatus 的第二个参数来始终获取用户的最新状态(对于删除您的应用的用户,这不会返回connected)。

    FB.getLoginStatus(function(response) {
      // this will be called when the roundtrip to Facebook has completed
    }, true);
    

    参见FB.getLoginStatus documentation“往返 Facebook 服务器”部分

    【讨论】:

    • 谢谢 Juicy,我正在阅读来自 developers.facebook.com/docs/reference/javascript/… 的文档,其中一种状态是用户已登录 FB,但尚未对我的应用程序进行身份验证,我认为其中一种情况可能是用户登录,验证我的应用程序,但在他的帐户设置之后立即将其删除,因此有一个“else if (response.status === 'not_authorized')”。我不确定为什么用户在删除我的应用程序时不应该登录?如果我错了,请纠正我。谢谢。
    • @user415795,好吧,一旦用户删除了您的应用程序,他在技术上仍处于登录状态,但是一旦您知道他不在,就应该注销(或提供返回的可能性) t 您的应用程序的用户了。使用FB.getLoginStatus 和等于true 的第二个参数将确保从Facebook 获取最新状态,并且您会意识到用户没有登录到您的应用程序这一事实。如果您在没有第二个参数的情况下调用FB.getLoginStatus,您将获得缓存authResponse,这可能不代表与用户连接的真实状态...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-17
    • 2013-02-19
    相关资源
    最近更新 更多