2013-05-22 3 views
0

페이스 북에서 사용자 정보를 얻으려고 노력하고 있는데, 누군가가 내 코드에 어떻게 넣어야하는지, 어디에서 볼 수 있습니까? FB.getLoginStatus와 페이스 북 튜토리얼에있는 다른 것들을 이미 사용해 봤는데, 내 코드에 어디에 넣어야할지 모르겠다. 나는이 유틸리티를 마운트의 끝 부분에 넣었지만 결코 그것을 HTML과 자바 스크립트 전에 일했습니다 .. 그래서 제발 도와주세요! 대단히 감사합니다!페이스 북에서 사용자 정보 가져 오기

<!DOCTYPE html> 
<html> 
    <head> 
     <meta name="viewport" content="text/html; charset=utf-8"> 

     <title>SlickQuiz Demo</title> 

     <link href="css/reset.css" media="screen" rel="stylesheet" type="text/css"> 
     <link href="css/slickQuiz.css" media="screen" rel="stylesheet" type="text/css"> 
     <link href="css/master.css" media="screen" rel="stylesheet" type="text/css"> 
     <link href="css/jquery.mobile-1.3.1.min.css" rel="stylesheet" type="text/css">  


    </head> 

    <body id="slickQuiz"> 
     <div data-role="header"> 
      <h1 class="quizName"><!-- where the quiz name goes --></h1> 
     </div> 
     <div data-role="content" class="quizArea"> 
      <div class="quizHeader"> 
       <!-- where the quiz main copy goes --> 

       <a class="button startQuiz" data-role="button" href="#" data-theme="b">Iniciar o teste!</a>    
      </div> 

      <!-- where the quiz gets built --> 
     </div>  

     <div class="quizResults"> 
      <h3 class="quizScore">Pontuação: <span><!-- where the quiz score goes --></span></h3> 

      <h3 class="quizLevel"><strong>Nível:</strong> <span><!-- where the quiz ranking level goes --></span></h3> 

      <div class="quizResultsCopy"> 
       <!-- where the quiz result copy goes --> 
      </div> 
     </div> 

     <script src="js/jquery.js"></script> 
     <script src="js/slickQuiz-config.js"></script> 
     <script src="js/slickQuiz.js"></script> 
     <script src="js/master.js"></script> 

     <fb:login-button show-faces="true" width="200" max-rows="1" perms="user_hometown,user_about_me,email,user_address" autologoutlink="true"></fb:login-button>  

     <div id="fb-root"></div> 
     <script src="http://connect.facebook.net/en_US/all.js"></script> 
     <script>   
      window.fbAsyncInit = function() { 
       FB.init({ 
       appId  : '245686095571989', // App ID 
       channelUrl : 'http://localhost:8080/SlickQuiz/', // Channel File 
       status  : true, // check login status 
       cookie  : true, // enable cookies to allow the server to access the session 
       xfbml  : true, // parse XFBML 
       oauth  : true 
       }); 

       FB.api('/me', function(response) { 
        alert(response.name); 
       }); 

       FB.Event.subscribe('auth.authResponseChange', function(response) { 
       if (response.status === 'connected') { 
        testAPI(); 
       } else if (response.status === 'not_authorized') { 
        FB.login(); 
       } else { 
        FB.login(); 
       } 
       }); 
      }; 

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

      function testAPI() { 
      console.log('Welcome! Fetching your information.... '); 
      FB.api('/me', function(response) { 
       alert('3'); 
       console.log('Good to see you, ' + response.name + '.'); 
       alert(response.name); 
      }); 
      }  

     </script>  
    </body> 
</html> 
+0

'FB.api' 방법은'fbAsyncInit' 기능 밖에해야 할 쉽게 변화되는이 링크를 시도하십시오 – ThePCWizard

답변

0

흠, 위의 코드에는 여러 가지가 있습니다. 왜 내가 필요한지 이해할 수 없습니다. 하나, 왜 oauth 사실을 준 이유가 무엇입니까? oauth를 사용하고 있습니까?

이 코드를 jsfiddle 페이지로 이동하여 작동 코드를 표시하려고 시도했지만 FB가 도메인 외부의 APPID 사용을 차단합니다. 참고로 http://jsfiddle.net/7Ekz9/

window.fbAsyncInit = function() { 
    FB.init({ 
    appId: '245686095571989', // App ID 
    status: true, // check login status 
    cookie: true, // enable cookies to allow the server to access the session 
    xfbml: true 
    }); 
    FB.login(function (response) { 
    console.log(response); 
    if(response.authResponse){ 
    testAPI(); 
    } 
    }); 
}; 

: 이것은 당신에게 당신이 필요로 무엇의 아이디어를 줄 것이다 나는 외부 자원으로 all.js로드. 당신도 시도해 볼 수 있습니다.

관련 문제