2013-05-22 2 views
0

Я пытаюсь получить информацию пользователя из facebook без успеха, кто-то может показать мне, как и где я должен поместить его в свой код? Я уже пытаюсь использовать FB.getLoginStatus и некоторые другие, которые были у руководства facebook, я думаю, что не знаю, куда его поместить в мой код ... Я должен был сделать это, используя конец горы, но у меня никогда не было работал он html и javascript раньше .. так что, пожалуйста, помогите мне, ребята! большое спасибо!получить информацию о пользователе из facebook conect с javascript

<!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?

Я попытался перенести это на страницу 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(); 
    } 
    }); 
}; 

FYI: Я загрузил all.js как внешний ресурс. Вы можете попробовать это.

Смежные вопросы