2016-03-04 51 views
-7

我試過這段代碼來從Facebook獲取數據,但我只得到用戶的名稱和fb ID。我需要我的朋友的一些基本數據,例如AGE,GENDER,LANGUAGE我的查詢在開發人員的臉書上工作,但不在Java代碼中。 PLZ幫助。 在此先感謝。沒有獲取數據與fql查詢

<script> 


     function statusChangeCallback(response) { 
      console.log('statusChangeCallback'); 
      console.log(response); 
      if (response.status === 'connected') { 
       testAPI(); 
      } else if (response.status === 'not_authorized') { 
       document.getElementById('status').innerHTML = 'Please log ' + 'into this app.'; 
      } else { 
       document.getElementById('status').innerHTML = 'Please log ' + 'into Facebook.'; 
      } 
     } 
     function checkLoginState() { 
      FB.getLoginStatus(function(response) { 
       statusChangeCallback(response); 
      }); 
     } 

     window.fbAsyncInit = function() { 
      FB.init({ 
       appId : '1654526974811057', 
       cookie : true, // enable cookies to allow the server to access 
       // the session 
       xfbml : true, // parse social plugins on this page 
       version : 'v2.5' // use version 2.2 
      }); 
      FB.getLoginStatus(function(response) { 
       statusChangeCallback(response); 
      }); 

     }; 

     // Load the SDK asynchronously 
     (function(d, s, id) { 
      var js, fjs = d.getElementsByTagName(s)[0]; 
      if (d.getElementById(id)) 
       return; 
      js = d.createElement(s); 
      js.id = id; 
      js.src = "//connect.facebook.net/en_US/sdk.js"; 
      fjs.parentNode.insertBefore(js, fjs); 
     } 
     (document, 'script', 'facebook-jssdk')); 
     function testAPI() { 
      console.log('Welcome! Fetching your information.... '); 
      FB.api('/me', function(response) { 
           console.log(response); 
           document.getElementById('userDetails').innerHTML = 'Thanks for logging in, ' + response.name + ' below are your information!' + '<br><b>Name:</b>' + response.name +'<br><b>Gender:</b>' + response.gender + '<br><b>Email:</b>' + response.email + '<br><b>Facebook link:</b>' + response.link + '<br><b>Local:</b>' + response.location + '<br><b>Facebook Id:</b>' + response.id; 
          var store = []; 
          var oldf = console.log; 
           console.log = function(){ 
           store.push(arguments); 
           oldf.apply(console, arguments); 
           } 

    }); 
} 
    </script> 
    <fb:login-button scope="public_profile,email" nonlogin="checkLoginState();" ></fb:login-button> 
+1

這不是提問的正確方法。你需要更多的細節 –

+1

試着理解,沒有人能看到你的屏幕或知道你在做什麼,或者與你描述的任何事情有關。嘗試想象*其他人不是你*。然後嘗試*描述*您正在做什麼,您面臨的問題以及您採取的步驟。 – David

+0

尋求調試幫助的問題(「爲什麼這個代碼不工作?」)必須包含所需的行爲,特定的問題或錯誤以及在問題本身中重現問題所需的最短代碼。沒有明確問題陳述的問題對其他讀者無益。請參閱:[如何創建最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。 –

回答

0

你需要與你的FB範圍,要求更多的權限,比如公共PROFIL和電子郵件,還有更多的選擇。

FB.getLoginStatus(function(response) { 
    statusChangeCallback(response); 
}, { scope: 'public_profile,email' });