如何在不调用FB.getLoginStatus的情况下获取facebook用户ID,并提示用户授予访问公共信息的权限

时间:2012-02-16 09:22:51

标签: facebook

我正在开发asp.net网站作为facebook应用程序。

我试图让“Facebook Like Gate”宣传用户像我的页面一样,他才能看到应用程序。例如https://www.facebook.com/AvonProductsInc?sk=app_188308831197082

问题是上面的应用程序并没有让我获得获取我的基本信息的许可,但是我必须让用户给我这样的许可才能使用以下代码来获取user_id并检查他是否已经获得了我的页面:

function checkFBlike() {

    //FB.login
    FB.getLoginStatus(function (response) {

        var r = response;

        if (response.status == "connected") {

            var user_id = response.authResponse.userID;
            var page_id = "341342102543433"; //341342102543433            168619489865949
            var fql_query = "SELECT uid FROM page_fan WHERE page_id = " + page_id + "and uid=" + user_id;
            var the_query = FB.Data.query(fql_query);

            the_query.wait(function (rows) {

                if (rows.length == 1 && rows[0].uid == user_id) {
                    //jQuery("#container_like").show();
                    fbLikeGateHide();
                    //here you could also do some ajax and get the content for a "liker" instead of simply showing a hidden div in the page.

                }
                else {

                    //and here you could get the content for a non liker in ajax...
                }
            });


        } else if (response.status === 'not_authorized') {
            // the user is logged in to Facebook, but not connected to the app
            showFbLogin();  //display Facebook Login button 

        }
        else {
            // user is not logged in
        }
    });


}

function showFbLogin(){
    FB.login(function(response) {
        var r=response;
    });
}

1 个答案:

答案 0 :(得分:1)

由于您将成为avon应用程序(特别是页面选项卡应用程序),您应该查看来自HTTP POST的signed_request参数,当您的页面是画布应用程序时,Facebook会执行此操作。你真的不需要做任何客户端检查。

有关signed_request的详细信息,请参阅:http://developers.facebook.com/docs/authentication/signed_request/