我正在尝试使用 PHP/FQL 选择所有共同朋友的连接。使用我的 UID(540 个朋友),这意味着 >12,000 个连接,其中 >6500 个是唯一的。因此,此代码应返回所有连接,但 Facebook 显然对 FQL 查询有 4999/5000 行限制。
// select mutual unique friends
$unique_connections = $facebook->api_client->fql_query("
SELECT uid1, uid2 FROM friend
WHERE uid1 IN
(SELECT uid2 FROM friend WHERE uid1=$uid)
AND uid2 IN
(SELECT uid2 FROM friend WHERE uid1=$uid)
");
我知道上面的数字是因为我编写的原始代码循环遍历我的朋友列表并为每个人发送一个 getMutualFriend 查询。
foreach ($friends as $key)
{
$mutual_friends = $facebook->api_client->friends_getMutualFriends($key);
foreach ($mutual_friends as $f_uid)
{
array_push($all_connections, array($key,$f_uid));
}
}
Of course it takes almost 3 minutes to run that script, while the FQL query returns in 5 seconds. After an hour of searching for this answer I've come to the conclusion the only way to get around this is to use a mixture of the two methods. Well that, and post here. Any ideas on a better way to write this script and beat the 4999/5000 row limit?
Here's an fql_multiquery that should do the same as above. It is also limited to 4999/5000.
$queries = '{
"user_friends":"SELECT uid2 FROM friend WHERE uid1 = '.$uid.'",
"mutual_friends":"SELECT uid1, uid2 FROM friend WHERE uid1 IN (SELECT uid2 FROM #user_friends) AND uid2 IN (SELECT uid2 FROM #user_friends)"
}';
$mq_test = $facebook->api_client->fql_multiquery(trim($queries));
print_r($mq_test);