facebook api 非常慢
我正在尝试制作一个应用程序,使用 facebook php sdk 从 Facebook 好友那里获取所有生日和其他信息。
我获取了好友列表,并使用 foreach 循环获取每个好友 ID 的所有信息。
这一切都有效,只需要 4 分钟以上即可获取所有信息。 (对于每个朋友,我都必须拨打新电话)
我不能指望我的应用程序的用户等待那么久。
有没有办法更快地获取信息。
这是我的代码:
//$arrFriends is a list with all id's and names of friends
foreach ($arrFriends as $f => $value)
{
echo('');
$fql = "select uid, email, name, hometown_location, sex, birthday, education, relationship_status, pic_square from user where uid=" . $value[id];
$param = array('method' => 'fql.query','query' => $fql,'callback' => '');
$friend = $facebook->api($param);
//dan opslaan in de database:
print_r($friend);
echo('
');
}
i'm trying to make an application, getting all the birthdays and other information from you facebook friends, using the facebook php sdk.
i get the friendlist and with a foreach loop, get all the info for every friends' id.
This all works, only it takes 4 min+ to get all the information.
(for every friend i have to make a new call)
I can't expect users of my application to wait that long.
Is there a way to get the info faster.
this is my code:
//$arrFriends is a list with all id's and names of friends
foreach ($arrFriends as $f => $value)
{
echo('');
$fql = "select uid, email, name, hometown_location, sex, birthday, education, relationship_status, pic_square from user where uid=" . $value[id];
$param = array('method' => 'fql.query','query' => $fql,'callback' => '');
$friend = $facebook->api($param);
//dan opslaan in de database:
print_r($friend);
echo('
');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
参考:https://developers.facebook.com/docs/reference/fql/< /a>
相同的结果,快速、快速、优雅的解决方案。愿演出与你同在。
另一个解决方案(为您提供一个想法)
如果您有数百个朋友,那么这是很正常的并且是预期的。您在循环中请求 Facebook API 数百次。
许多可扩展的 Facebook 应用程序在后台异步执行该工作(在任务队列中),或者可能完全在不同的计算机上执行,以免减慢速度并消耗 CPU 突发。
尝试在 FQL 查询中使用
OR
连接词。但在这种情况下,您的 FQL 查询会变得越来越大,因此您必须对其进行划分。因此使用第一种解决方案。
You can use
Reference: https://developers.facebook.com/docs/reference/fql/
Same result, fast, quick, elegant solution. May the performance be with you.
Another solution (to be an idea for you)
If you have hundreds of friends, well that's pretty normal and expected. You're requesting Facebook API for hundres of times in the loop.
Many scalable facebook applications do that job asynchronously in the background (in a task queue) or maybe completely on a different machine to not to slow down and consume CPU bursts.
Try to use
OR
conjuctives in your FQL queries.But in this case your FQL query gets larger and larger so that you have to be divide it. Therefore use first solution.
每个 fql 查询都涉及到 facebook 的 http 请求,这可能很慢。
如果您可以制定一个查询以在单个响应中生成所有结果,然后在循环中处理该响应,您可能会获得更好的性能。
Each fql query involves an http request to facebook, which is likely to be slow.
If you can work out a query to produce all of the results in a single response, and then process that response in a loop, you are likely to get much better performance.
如果您不想使用 FQL,批量请求 的设计目的正是为了这个目的。您构建一系列图形请求并将它们一起发送。根据文档,它们是并行处理的。
If you don't want to use FQL, batch requests are designed for exactly this purpose. You build an array of graph requests and send them together. According to the documentation they're processed in parallel.