2013-02-23 3 views
0

여기에 코드 입력 난 C# 용 페이스 북 튜토리얼을 읽고 액세스 토큰을 얻었으며 방금 얻었지만 이벤트 처리에 대한 자습서의 단계를 이해할 수없는 것 같습니다. 방향 전환. 나는 C#에서 JavaScript를 사용하는 그런 일은 결코하지 않았다.Facebook 로그인 후 리디렉션 C#

<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() { 
     FB.init({ 
      appId: '{app Id}', // 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> 

뿐만 아니라 페이스 북 버튼 모든 작품은 튜토리얼에 따라, 다음 찾을으로 Here 내가 토큰을 받고 리디렉션 "다음, 페이지, 액션, 또는 핸들러를 작성해야합니다 나는 다음이 이 예제에서는 일반 핸들러를 생성합니다. "

public class FacebookLogin : IHttpHandler, System.Web.SessionState.IRequiresSessionState { 

    public void ProcessRequest(HttpContext context) { 
     var accessToken = context.Request["accessToken"]; 
     context.Session["AccessToken"] = accessToken; 

     context.Response.Redirect("/MyUrlHere"); 
    } 

    public bool IsReusable { 
     get { return false; } 
    } 
} 

나는 단순히 내 코드에서 뒤에 넣어하지만 아무것도하지 않았다

그들은이 사용합니다. 나는 여기서 정말로 무엇을해야할지 모르겠습니다.

var accessToken = Session["AccessToken"].ToString(); 
var client = new FacebookClient(accessToken); 
dynamic result = client.Get("me", new { fields = "name,id" }); 
string name = result.name; 
string id = result.id; 
+0

을가 FB.Event.subscribe과 같은 몇 가지 테스트를 수행 한 후 ('auth.authResponseChange', 기능 (응답) – KJ3

+0

이 작업 메신저가 작동하고 있지만 지금은 사용자가 사이트를 다시 등록 할 때 다시 로그인하는 방법을 이해하지 못합니다. – rogue39nin

답변

0

당신이 파일 뒤에 aspx.cs 코드에서 FacebokLogin 핸들러를 넣지 마십시오 확인 : 어떻게 이런 식으로 뭔가를 할 수 있도록 내 페이지가 새 페이지로 리디렉션받을 수 있나요. 별도의 .ashx 파일이어야합니다.

FB.Event.subscribe ('auth.authResponseChange', function (response) {...}가 호출되지 않는다고하셨습니다.) FB에서 apiKey : "[OAuth token goes here]"를 포함 해보십시오. 초기화. 확실하지가 작동하지만 그것이 샷 가치가있을 것입니다 경우.

FB.init({ 
    appId: '{app Id}', // App ID 
    status: true, // check login status 
    cookie: true, // enable cookies to allow the server to access the session 
    xfbml: true, // parse XFBML 
    apiKey: "92834yv221985vn4139y845vn19835vynv519835vn" 
}); 
관련 문제