Facebook +仅提示发布流

时间:2012-09-23 11:47:48

标签: javascript facebook

如果我的用户已经登录到Facebook但是从他/她的帐户中删除了我的应用程序,那么只有在用户已经登录后再次进入我的应用程序时,我才能提示使用publish_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' });
            };
        });
    }  

1 个答案:

答案 0 :(得分:0)

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

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

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


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

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

请参阅"往返于Facebook的服务器" 部分FB.getLoginStatus documentation