1
我試圖在Javascript中構建一個Facebook應用程序,它可以讓我通過使用FQL檢索每個朋友的狀態列表。但似乎沒有結果從每個FQL查詢返回。這裏是我的代碼,從不同的教程模板拼湊起來:如何使用Javascript + FQL獲取朋友的Facebook狀態?
<html>
<title>Testing Facebook Javascript SDK</title>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : 'MY_APP_ID', // App ID from the App Dashboard
channelUrl: '//www.myurl.net/channel.html',
status : true, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true // parse XFBML tags on this page?
});
// Additional initialization code such as adding Event Listeners goes here
FB.getLoginStatus(function(response){
if (response.status === 'connected'){
showMyFriends();
FB.api('/me/permissions',function(response){
console.log(response);
});
} else if (response.status === 'not_authorized'){
login();
} else {
login();
}
});
};
function login(){
FB.login(function(response){
if (response.authResponse){
alert('login');
} else {
alert('cancelled');
}
},{scope:'read_stream'});
}
function showMyFriends(){
FB.api('/me/friends',function(response){
if(response.data){
var length = response.data.length;
for(var i=0;i<50;i++){
element=response.data[i];
getAFriendStatus(element.id);
}
}
});
}
function getAFriendStatus(friendUID){
FB.api('/fql',{q:{"query1":"select message from status where uid="+friendUID}},
function(response){
console.log(response);
}
);
}
// Load the SDK's source Asynchronously
// Note that the debug version is being actively developed and might
// contain some type checks that are overly strict.
// Please report such bugs using the bugs tool.
(function(d, debug){
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 = "https://connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));
</script>
</body>
當我檢查控制檯,我得到的每次調用getAFriendStatus()
是:
Object {data: Array[1]}
data: Array[1]
0: Object
fql_result_set: Array[0]
name: "query1"
__proto__: Object
length: 1
__proto__: Array[0]
__proto__: Object
因爲fql_result_set
的大小爲0 ,我認爲我的查詢存在問題。我不認爲這是一個權限問題,因爲FB.api('/me/permissions')
控制檯輸出爲:
Object {data: Array[1], paging: Object}
data: Array[1]
0: Object
basic_info: 1
installed: 1
read_stream: 1
所以我知道我有read_stream
權限。爲什麼我沒有得到這個查詢的狀態?
編輯:我只是想在FQL查詢與
"select message from status where uid=me()"
,我得到了所有我最近的狀態職位。這似乎只是讓我的朋友的狀態問題?這可能是由於他們的隱私設置?