Facebook互相朋友和FQL 4999/5000记录限制 [英] Facebook mutual friends and FQL 4999/5000 record limit
问题描述
我正在尝试使用PHP / FQL选择所有共同的朋友的连接。使用我的UID(540个朋友),这意味着> 12,000个连接,其中> 6500是唯一的。所以这个代码应该返回所有的连接,但Facebook显然对FQL查询有一个4999/5000的行限制。
I'm trying to select all mutual friends' connections with PHP/FQL. Using my UID (540 friends), which means >12,000 connections, of which >6500 are unique. So this code should return all the connections but Facebook apparently has a 4999/5000 row limit on FQL queries.
// 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查询对于他们每个人
I know the numbers above because the original code I wrote loops through my friend list and sends a getMutualFriend query for each of them.
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));
}
}
当然,运行该脚本大约需要3分钟而FQL查询在5秒内返回。经过一个小时的搜索之后,我得出结论,唯一的办法是使用这两种方法的混合。那么,并在这里发贴。任何想法,以更好的方式写这个脚本,并击败4999/5000行限制?
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?
这是一个fql_multiquery应该做同样的上面。它也限于4999/5000。
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);
推荐答案
所以,我发布答案给我的原始题。我可以通过块化UID数组(使用适当命名的array_chunk()PHP函数)绕过FQL查询的5000行限制,并循环遍历块执行小型查询,然后将其全部还原到一个数组。整个脚本平均14秒,超过12000行,这是一个巨大的进步。您可以在这里查看应用程序: givememydata.com
So, I'm posting the answer to my original question. I was able to circumvent the 5000 row limit on FQL queries by chunking the array of UIDs (using the appropriately-named array_chunk() PHP function) and looping through the chunks to execute mini-queries, and then appending it all back into one array. The whole script averages 14 seconds for over 12,000 rows so that is a huge improvement. You can see the application at work here: givememydata.com
哦,和Facebook应该重新考虑他们(仍然没有记录)的FQL行限制。在他们的服务器上更多的是什么?在5秒内执行的单个查询或需要180秒的500个查询?对不起,不得不泄漏。 ; - )
Oh, and Facebook should reconsider their (still undocumented) FQL row limit. What is more taxing on their servers? A single query that executes in 5 seconds or 500 queries that take 180 seconds? Sorry, had to vent. ;-)
这篇关于Facebook互相朋友和FQL 4999/5000记录限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!