0

我尝试跟随一位导师,该导师展示了如何拥有登录按钮以及如何登录 FB。

代码如下 -

<script type="text/javascript">
    window.fbAsyncInit = function () {
        FB.init({
            appId: '521597764587246', // App ID
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true  // parse XFBML
        });

        // Additional initialization code here

        FB.Event.subscribe('auth.authResponseChange', 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
                var uid = response.authResponse.userID;
                var accessToken = response.authResponse.accessToken;

                // TODO: Handle the access token

                // Do a post to the server to finish the logon
                // This is a form post since we don't want to use AJAX
                var form = document.createElement("form");
                form.setAttribute("method", 'post');
                form.setAttribute("action", '/FacebookLogin.ashx');

                var field = document.createElement("input");
                field.setAttribute("type", "hidden");
                field.setAttribute("name", 'accessToken');
                field.setAttribute("value", accessToken);
                form.appendChild(field);

                document.body.appendChild(form);
                form.submit();

            } 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.
            }
        });

    };

    // 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>

我想要实现的是允许在用户墙上写字。

登录时如何获得其他权限?

4

1 回答 1

0

这是一个请求“发布流”权限的 facebook 身份验证,这是您代表 facebook 用户发布状态更新所需的权限。

FB.getLoginStatus(function (response) {
        if (response.status == "connected") {
            //User is logged into facebook and has authorized your app proceed with wall post
        });
} else if (response.status == "not_authorized") {
    //User is logged in to facebook but has not authorized your app
} else if (response.status == "unknown") {
    //User is not logged in to facebook
}
});

//This example uses jQuery and a button with id="#fb-login-button", just put the contained code below in whatever click handler your using for your facebook login button
$("#fb-login-button").click(function () {
    FB.login($.proxy(function (response) {
        if (response.authResponse) {
            //User has autorized proceed with wall post
        } else {
            //User did not autorize
        }
    }, this), {
        //Scope is where you specify permissions
        scope: 'publish_stream'
    });
});
于 2013-10-12T07:33:28.000 回答