【问题标题】:Log out of my site with facebook c# sdk - but not out of Facebook completely?使用 facebook c# sdk 退出我的网站 - 但不能完全退出 Facebook?
【发布时间】:2012-06-22 15:14:04
【问题描述】:

我正在使用 Facebook C# SDK 来允许用户使用 Facebook 登录我的网站。

要注销,我可以使用 fb.logout,但这会将用户从 facebook 和我的网站中注销,这对用户来说似乎真的很烦人且不必要。

我非常有信心,当他们注销我的网站时,他们不必注销 Facebook,因为 digg.com 提供了我所追求的功能 - 使用 facebook 登录和注销,无需登录用户退出其 Facebook 帐户。

这是我用于登录/注销的代码:

<div id="fb-root"></div>
    <script>
        window.fbAsyncInit = function () {
            FB.init({
                appId: 'XXXXXXXXXXXX', // App ID
                status: true, // check login status
                cookie: true, // enable cookies to allow the server to access the session
                xfbml: true  // parse XFBML
            });

            // Handle successful log in.
            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;

                    // 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", '/login.aspx');

                    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
                    alert("Logged in to facebook but not authenticated MT");
                } 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>

  <div class="fb-login-button" autologoutlink="true"></div>

您会看到,当用户登录时,我重定向到 /login.aspx,它提供了我的站点的登录功能(使用 .net 身份验证),并将 accesstoken 保存到会话中以供用户会话期间使用。

我需要注销按钮来执行相同的操作,但相反,无需将用户完全从 facebook 注销。

我在网上找了几个小时,但似乎找不到任何方法来调用 fb.logout 而不让用户也退出他们的 Facebook 帐户。如果 digg.com 能做到,那我肯定也能做到吧?

非常感谢,

保罗

【问题讨论】:

    标签: facebook facebook-graph-api facebook-c#-sdk


    【解决方案1】:

    我非常有信心,当他们退出我的网站时,他们不必退出 Facebook

    Facebook Platform Policies 否则 - I 部分。特性和功能,#6

    您的网站必须提供明确的“注销”选项,该选项也会使用户退出 Facebook。

    【讨论】:

    • 啊,好的。我猜 digg.com 不介意违反政策。那么这使得这非常简单 - 非常感谢您的帮助。保罗
    猜你喜欢
    • 1970-01-01
    • 2012-07-26
    • 1970-01-01
    • 2017-08-29
    • 1970-01-01
    • 1970-01-01
    • 2011-12-02
    • 2011-12-04
    • 1970-01-01
    相关资源
    最近更新 更多