我目前正在使用Facebook的PHP API来收集共同朋友的数据。我目前正在按照此处的建议进行查询:Facebook 共同朋友和 FQL 4999/5000 记录限制,使用 array_chunk 方法。我可以问一下抛出上述错误的可能原因是什么吗?可能的资源限制是什么?
起初,我试图将 php 脚本的内存限制增加到 128MB,但我使用了 memory_get_usage(true),当我发现上述 Facebook 错误时,它给了我一个比这个数字少得多的数字(转换后,它小于 3MB)。
这是由于Facebook或我的脚本造成的资源限制吗?
这是我编写的代码:
$chunked_friends = array_chunk($all_friends_id, 100); // we use 100 for now, if there is loss of information, then we consider another way
foreach ($chunked_friends as $array) {
$mutualfriends = $facebook->api(array(
'method' => 'fql.query',
'query' => 'SELECT uid1, uid2 FROM friend
WHERE uid2 IN
(SELECT uid2 FROM friend WHERE uid1=me())
AND uid1 < uid2
AND uid1 IN ( '. implode(', ', $array) .' )'
));
foreach ($mutualfriends as $mutualfriend) {
$returned_array["links"][] = array("source" => $mutualfriend['uid1'], "target" => $mutualfriend['uid2']);
}
usleep(200000);
}
编辑:我目前正在使用heroku来开发我的应用程序。
这是由于Facebook造成的资源限制吗
是的。
检查应用见解("API"部分),了解它是否特定于您的应用程序(给定时间段内请求过多/过大)。
最后,我使用了批处理请求,这似乎已经解决了问题。我不确定什么是太多的 API 调用,因为 FB 也没有真正说。