在试图从facebook帐户中获取好友列表时,我很幸运得到一些不可理解的回复,这就是我在console.log时所得到的:
#v_3 { __wrapped=#v_3, __observableEvents={...}, name="v_3", more...}
The method FB.Data.query:toString is not officially supported by Facebook and access to it will soon be removed.
这是我的登录代码并获取用户的好友列表成员:
FB.init({ appId:'my_appid' });
// fetch the status on load
FB.getLoginStatus(handleSessionResponse);
$('#login').bind('click', function() {
FB.login(handleSessionResponse);
});
$('#logout').bind('click', function() {
FB.logout(handleSessionResponse);
});
// handle a session response from any of the auth related calls
function handleSessionResponse() {
FB.api('/me', function(response) {
var access_token = FB.getAuthResponse()['accessToken'];
console.log(access_token);
console.log(response);
var friends = FB.Data.query('SELECT uid, flid FROM friendlist_member WHERE flid IN (SELECT flid FROM friendlist WHERE owner=me())');
console.log(friends);
$('#user-info').html(response.id + ' - ' + response.name);
});
}
任何人都有同样的问题吗?
答案 0 :(得分:3)
嗯,有一个更好的方法来获取用户的好友列表:
FB.api('me/friends', function(response) {
console.log(response);
}
如果你真的想使用FQL(在这种情况下这不是一个好方法),我们将解释如何在这个帖子中使用FQL和JavaScript SDK:How can I execute a FQL query with Facebook Graph API
获取朋友的正确FQL调用将是这样的:
SELECT uid2 FROM friend WHERE uid1=me()