facebook sdk Asp.net并使用" Facebook SDK for .NET和ASP.NET入门"

时间:2014-03-28 17:10:03

标签: c# asp.net facebook facebook-javascript-sdk

我正在尝试创建我的第一个facebook sdk Asp.net并使用" Facebook SDK for .NET和ASP.NET"作为指南位于这里:

我遇到的问题是在FB.init()和FB.Event.subscribe()之后,我不认为事件中的函数被调用,所以没有回复我的Webform1 .aspx所以我可以获得accessToken。

我确实读过这篇文章,但他们遇到了一个不同的问题,就是突破了登录循环:

以下是执行WebForm1.aspx时发生的事件:

  1. 我在不同地方设置了断点
  2. 我在VS 2012中点击F5跑步
  3. 加载WebForm1.aspx
  4. void Page_Load被正确调用
  5. FB.init()被称为
  6. FB.Event.subscribe()被称为
  7. Facebook登录图像显示在WebForm1.aspx
  8. 我点击了facebook登录图片
  9. 显示
  10. https://www.facebook.com/login.php
  11. 我提供了用于获取AppID的凭据
  12. 点击右下角的“登录”按钮
  13. 我收到一个对话框,指出您正在查看的页面正在尝试  关上窗户。要关闭此窗口吗?"
  14. 我选择是
  15. 它将我带回WebForm1.aspx
  16. void Page_Load未被调用,因为没有回发
  17. accessToken中没有发布值。

    <script>
    window.fbAsyncInit = function () {
        FB.init({
            appId: '6453703688*****', // App ID
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true  // parse XFBML
        });
    
        alert("about to subscribe to event");
        // Additional initialization code here
        FB.Event.subscribe('auth.authResponseChange', function (response) {
            alert(response.status);
            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');
                form.setAttribute("action", 'WebForm1.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("has not authenticated your app");
            } else {
                // the user isn't logged in to Facebook.
                alert("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));
    

0 个答案:

没有答案