2012-11-16 6 views
0

안녕하세요 저는 facebook APP에 처음입니다. Facebook C# SDK 및 Javascript SDK에서 작업하고 있습니다. 하지만 문제는 AccessToken을 얻을 수없고 코드를 디버깅 할 수 없다는 것입니다. 아래 코드를 찾으십시오.accessToken을 수신 할 수없고 심지어 getLoginStatus 이벤트를 시작할 수 없습니까?

<div id="fb-root"></div> <!-- This initializes the FB controls--> 
<script> 
    window.fbAsyncInit = function() { 
     FB.init({ 
      appId: 'XXXXXXXXXXXXXXX', // 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 
     alert("Additional initialization code here"); 
     FB.Event.subscribe('auth.login', function (response) 
     { 
      debugger; ****//Debugger is not Raising**** 
      if (response.status === 'connected') { 
       // connected 
       alert("Connected"); 
      } else if (response.status === 'not_authorized') { 
       // not_authorized 
      } else { 
       // not_logged_in 
      } 
     }); 

     FB.getLoginStatus(function (response) { 
      if (response.session) { 
       // logged in and connected user, someone you know 
       alert("Connected"); 
      } else { 
       // no user session available, someone you dont know 
      } 
     }); 

     FB.Event.subscribe('auth.authResponseChange', function (response) { 
      alert("Additional initialization code here"); 
      if (response.status === 'connected') { 
       alert("Bhuvan"); `// Event Not Raising` 
       // 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 
       debugger; 
       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.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 
      } 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" data-show-faces="true" data-width="400" data-max-rows="1"></div> 

로그인 할 수 있지만 이벤트를 처리 할 수 ​​없습니다. 왜 내가 이벤트를 일으킬 수 없는지 그리고 왜 내가 엑세스 코드를 찾을 수 없는지 알 수 있습니까?

+0

PLS는에서 볼 불을 지르고 또는 Crome 스 콘솔 어떤 JS 오류가이 경우 여기를 붙여 넣기를 channel.html라는 HTML 파일을 만듭니다. – sajanyamaha

답변

1

먼저로드 SDK 비동기이 선 위에 즉, 스크립트 위 를이 코드 청크를 추가하여 window.fbAsyncInit = function() {

이 추가 :

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

는 또한 FB.init 내부 채널 파일을 추가 ({}) ;

channelUrl: '//' + window.location.hostname + '/Beta/channel.html', // Path to your Channel File LIVE 

는 루트 폴더에 파일 내용

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head> 
    <title>Untitled Page</title> 
    <script src="//connect.facebook.net/en_US/all.js"></script> 
</head> 
<body> 

</body> 
</html> 
+0

이것은 작동하지 않습니다 ..? 채널 파일은 무엇이되어야합니까? 다른 ASPX 페이지를 만들었습니다. 채널 URl에 channelUrl로 연결되었습니다. '//'+ window.location.hostname + '/FaceBookIntegration/WebForm1.aspx', 맞습니까? – Bhuvan

+0

pls 채널 파일 내용에 대한 위의 대답에 대한 편집 내용을 참조하십시오. – sajanyamaha

+0

아니요 :(여전히 작동하지 않습니다.) – Bhuvan

관련 문제