获取Facebook好友列表,同时也排除一些

时间:2012-06-22 00:17:16

标签: php mysql facebook facebook-fql facebook-php-sdk

我正在使用PHP SDK进行FQL调用以提取用户朋友的列表。它看起来像这样:

$all_friends = $facebook->api(array('method' => 'fql.query', 'query' => 'SELECT uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) ORDER BY name ASC'));

这很有效,但现在我也想从列表中排除一些朋友。我已经尝试了我认为有效的但看起来不起作用(它返回一个空列表)。

作为我正在尝试做的一个例子:

$all_friends = $facebook->api(array('method' => 'fql.query', 'query' => 'SELECT uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND uid NOT IN (12345,54218,68151) ORDER BY name ASC'));

有什么我想念的吗?感谢。

2 个答案:

答案 0 :(得分:1)

“NOT IN”不是FQL支持的功能。 Graph API Explorer抛出异常:(#601)分析器错误:位置92处出现意外“不”。

您可以使用IN

进行简单的选择
$all_friends = $facebook->api(array('method' => 'fql.query', 'query' => 'SELECT uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) ORDER BY name ASC'));

并使用PHP过滤掉使用ID。据我所知,这是唯一的方法。

我找到了相关帖子:链接here

答案 1 :(得分:1)

这可以使用下一个FQL查询:

SELECT uid, name FROM user WHERE uid IN (
  SELECT uid2 FROM friend WHERE uid1 = me() 
) AND NOT ( uid IN ('13892588847', '10004291510061', '1000753466073'))
ORDER BY name ASC

Graph API Explorer上尝试。