0

我有Django應用程序,我需要顯示其Facebook頁面的追隨者數量。 在我的base.html中,我已經對FB追隨者的數量進行了硬編碼,但這不是一個可行的長期解決方案。使用Graph Api和Javascript SDK獲取Facebook頁面追隨者的數量

我一直在嘗試與內嵌的JavaScript,這是我的代碼的狀態:

<script> 
 
\t \t \t window.fbAsyncInit = function() { 
 
\t \t \t \t FB.init({ 
 
\t \t \t \t \t appId  : 'NumOfMyId', 
 
\t \t \t \t \t xfbml  : true, 
 
\t \t \t \t \t version : 'v2.4' 
 
\t \t \t \t }); 
 
\t \t \t \t FB.api(
 
\t \t \t \t \t '/MyWebSite', 
 
\t \t \t \t \t 'GET', 
 
\t \t \t \t \t {"fields":"likes"}, 
 
\t \t \t \t \t function(response) { 
 
\t \t \t \t \t \t console.log(response); 
 
\t \t \t \t \t \t //here should go something so that the number of people liking the page gets appended to an html element by id; 
 
\t \t \t \t \t }); 
 
\t \t \t }; 
 

 
\t \t \t (function(d, s, id){ 
 
\t \t \t \t var js, fjs = d.getElementsByTagName(s)[0]; 
 
\t \t \t \t if (d.getElementById(id)) {return;} 
 
\t \t \t \t js = d.createElement(s); js.id = id; 
 
\t \t \t \t js.src = "//connect.facebook.net/en_US/sdk.js"; 
 
\t \t \t \t fjs.parentNode.insertBefore(js, fjs); 
 
\t \t \t }(document, 'script', 'facebook-jssdk')); 
 
\t \t \t </script>

我需要Facebook的API給我的追隨者的數量,這是在圖形API瀏覽器中不是問題,但我不知道如何在我的標籤中完成它。

任何示例/建議或重定向到類似的解決問題/問題/ github項目將超級讚賞!

〜良好的共鳴,以你們

回答

0

如果你在你的頁面上使用jQuery,你可以做這樣的事情:

<p>The total number of likes in my page is <span id="number-of-likes"></span>.</p> 


function(response) { 
    console.log(response); 
    $('#number-of-liles').html(response.NUMBER_OF_LIKES_FIELD); 
}); 

哪裏response.NUMBER_OF_LIKES_FIELD是具有數正確的字段名稱的喜歡。

相關問題