2014-04-11 54 views
1

的FQL查詢這是我的查詢:運行使用Facebook的的JavaScript SDK

select uid, name, is_app_user from user where uid in (select uid2 from friend where uid1=me()) and is_app_user=1 

,我需要使用JavaScript SDK來運行它。我該怎麼做呢?我不確定語法和格式。當我在Open Graph Explorer(FBL部分)中運行它時,上面的FQL查詢起作用,但我無法設法讓它在Graph API部分中工作。

感謝

回答

3

您可以通過JS SDK(https://developers.facebook.com/docs/javascript/reference/FB.api)的FB.api()方法,通過使用

/fql?q= 

端點如果URL編碼查詢這樣

運行此
/fql?q=select%20uid%2C%20name%2C%20is_app_user%20from%20user%20where%20uid%20in%20(select%20uid2%20from%20friend%20where%20uid1%3Dme())%20and%20is_app_user%3D1&access_token={YOUR_USER_ACCESS_TOKEN} 

JS代碼看起來像這樣:

FB.api('/fql?q=select%20uid%2C%20name%2C%20is_app_user%20from%20user%20where%20uid%20in%20(select%20uid2%20from%20friend%20where%20uid1%3Dme())%20and%20is_app_user%3D1&access_token={YOUR_USER_ACCESS_TOKEN}', function(response) { 
    console.log(response); 
}); 

不要忘記添加您的訪問令牌!

+0

很好,謝謝!該編碼如何工作?有沒有一個JS函數可以用來編碼我的查詢? – Taimur

+1

使用encodeURIcomponent() – Tobi

2

通過FB.api執行查詢 -

FB.api("/fql?q="+encodeURIComponent('{your-query}'), function(response) { 
    if (!response || response.error) { 
    console.log('Error occurred: '+response.error.message); 
    } else { 
    console.log(response); 
    } 
});