我試圖從我的facebook頁面獲取所有的飼料白色的JavaScript API。 有沒有人有一個工作的例子?用javascript api在我的網頁上顯示我的來自Facebook的提要?
我已經嘗試過,但我不能得到它的權利,我可以從相冊中獲得照片,但我不能得到飼料,我不知道我做錯了什麼。
任何輸入真的很感激。謝謝!
我有這樣的代碼:
編輯
OK,我有初始化代碼中的代碼如下圖所示,它不工作,不執行代碼和我沒有得到任何錯誤:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<%=facebookAppId%>', // App ID
channelUrl : 'www.mypage.se/channel.html', // 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
});
// get the wall - feed
var page_id = '<%=facebookPageId%>';
FB.api('/' + page_id, {fields: 'access_token'}, function(resp2) {
if(resp2.access_token) {
alert(resp2.access_token);
FB.api('/page id/feed?access_token='+resp2.access_token, function(response) {
var ul = document.getElementById('feed');
for (var i=0, l=response.data.length; i<l; i++) {
var
feed = response.data[i],
li = document.createElement('li'),
a = document.createElement('a');
a.innerHTML = feed.message;
a.href = feed.link;
li.appendChild(a);
ul.appendChild(li);
}
});
}
});
};//end window.fbAsyncInit
// Load the SDK Asynchronously
(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));
</script>
所以我爲什麼會有例如: FB.api( '/ Facebook的ID',函數(重警報('你的名字是'+ response.name); }); 裏面的init代碼而不是其他代碼?
我仍然需要一些結構幫助在頁面上寫出回調,所以它看起來不錯,因爲它在Facebook上。 我喜歡寫出「消息,圖片,鏈接,名稱」,也許還有別的嗎?
正如我測試獲取這個例子中的消息,並且一些回調在頁面上顯示爲「undefined」?這是否意味着我收到消息時沒有任何價值? 如果是這樣我怎麼能不寫出emty值 - 未定義的?
謝謝!
UPDATE:
如果我用這個代碼,然後它會讀取的飼料,但只有林登陸到Facebook? 我開始感到困惑,因爲我認爲上面的代碼應該可以工作: 我首先在第一次調用時要求訪問令牌,當我得到訪問令牌時,然後在第二次調用中使用它,我在做什麼錯誤?
FB.api('/my userid or pageid/feed?access_token=the acces token that I get from the Graph API Explorer', {limit:5} , function(response){
if (response && response.data && response.data.length){
alert(response.message);
var ul = document.getElementById('feed');
for (var j=0; j<response.data.length; j++){
var feed = response.data[j],
li = document.createElement('li'),
a = document.createElement('a');
a.innerHTML = feed.message;
a.href = feed.link;
li.appendChild(a);
ul.appendChild(li);
}
}
});
- 我得到幾個不確定的答覆,我怎麼能不把它們寫出來的頁面上?
- 即使訪問該網頁的用戶沒有登錄到Facebook,我如何才能獲得上述代碼的工作?
- 我撥打其他電話,可以毫無問題地獲取相冊中的照片並將其顯示在網頁上,我不明白爲什麼不同?
- 如果我想爲客戶進行設置(完成時),我需要採取哪些步驟?有點困惑... :-)
- 我想通過電話 得到消息,圖片,喜歡等,並顯示它就像它在飼料牆上,這裏的任何建議嗎?
好吧,我終於得到了它:-) 工作,我得到了正確的存取權限令牌,現在我可以顯示飼料。 我在這裏得到了正確的標記: https://graph.facebook.com/oauth/access_token?client_id=myapp_id&client_secret=myapp_secret&grant_type=client_credentials 現在我可以使用下面的代碼獲取用戶訂閱源和頁面訂閱源,只需更改page_id!
var page_id = '<%=facebookPageId%>';
var pageaccessToken='xxxxxxxxxxxxxxxxxxxxxxxxxx';
FB.api('/' + page_id + '/feed?access_token='+ pageaccessToken, {limit:5} , function(response){
if (response && response.data && response.data.length){
var ul = document.getElementById('pagefeed');
for (var j=0; j<response.data.length; j++){
var feed = response.data[j],
li = document.createElement('li'),
a = document.createElement('a');
a.innerHTML = feed.message;
a.href = feed.link;
li.appendChild(a);
ul.appendChild(li);
}
}
});
好吧,現在它的工作,但我得到了未定義的響應? 這是什麼原因造成的,是因爲它是一個空值,我得到了迴應? 我該怎麼做才能使它不顯示在頁面上?
你能分享一些代碼嗎? – Neelam 2012-03-12 12:33:54
你有「read_stream」權限嗎? – 2012-03-12 13:18:31
是的,我擁有所有權限。 – 2012-03-12 16:29:38