여기에 코드 입력 난 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;
을가 FB.Event.subscribe과 같은 몇 가지 테스트를 수행 한 후 ('auth.authResponseChange', 기능 (응답) – KJ3
이 작업 메신저가 작동하고 있지만 지금은 사용자가 사이트를 다시 등록 할 때 다시 로그인하는 방법을 이해하지 못합니다. – rogue39nin