1

我是新來的Facebook SDK,我需要從公司Facebook頁面檢索5個最新狀態更新。我不知道從哪裏開始或做什麼,所以任何幫助都將受到高度讚賞。使用Facebook獲取最新的5個狀態更新javascript sdk

這就是我能夠從developer.facebook.com得到:

<script type="text/javascript"> 
     window.fbAsyncInit = function() { 
      // init the FB JS SDK 
      FB.init({ 
       appId: [my app id], 
       channelUrl: 'http://localhost:30125/Default.aspx', 
       status: false,         
       xfbml: true 
      }); 

      // Additional initialization code such as adding Event Listeners goes here 



     }; 

     // 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/all.js"; 
      fjs.parentNode.insertBefore(js, fjs); 
     }(document, 'script', 'facebook-jssdk')); 


    </script> 

回答

1

使用這裏提到的登錄代碼:https://developers.facebook.com/docs/facebook-login/getting-started-web/添加登錄代碼一部分。

然後編輯您的testAPI() -

function testAPI() 
{ 
    console.log('Welcome! Fetching your information.... '); 
    FB.api('/me', function(response) 
    { 
     console.log('Good to see you, ' + response.name + '.'); 
    }); 
    FB.api('/cocacola/feed?limit=5', function(response) 
    { 
     for (var i=0; i<response.data.length; i++) 
     { 
     console.log(i + " : " + response.data[i].message); 
     } 
    }); 
} 

Live Demo

得到的參數feed列表支持:Feed

的實現是很簡單的,自我的理解,讓我知道,如果你使用這個找到任何困難。

+0

所以我應該使用訪問令牌,而不是appId? 例如。 FB.init({access_token:[access token]', channelUrl:'http:// localhost:30125/Default.aspx', status:false, xfbml:true, oauth:true //查找社交插件 }); –

+0

不,您必須在'FB.init()'中編寫'appId'' –

+0

我運行它時出現此錯誤/警告:「fb-root」div尚未創建,自動創建。任何想法爲什麼? –