facebook api 非常慢

发布于 2024-11-07 03:47:22 字数 853 浏览 0 评论 0原文

我正在尝试制作一个应用程序,使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

何其悲哀 2024-11-14 03:47:22

您可以使用

SELECT uid, name, pic_square FROM user WHERE uid = me()
OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me())

参考:https://developers.facebook.com/docs/reference/fql/< /a>

相同的结果,快速、快速、优雅的解决方案。愿演出与你同在。


另一个解决方案(为您提供一个想法)

如果您有数百个朋友,那么这是很正常的并且是预期的。您在循环中请求 Facebook API 数百次。

许多可扩展的 Facebook 应用程序在后台异步执行该工作(在任务队列中),或者可能完全在不同的计算机上执行,以免减慢速度并消耗 CPU 突发。

尝试在 FQL 查询中使用 OR 连接词。

$fql = "select [...] from user where uid=123213312 OR uid=129038823 OR uid=893423890

但在这种情况下,您的 FQL 查询会变得越来越大,因此您必须对其进行划分。因此使用第一种解决方案。

You can use

SELECT uid, name, pic_square FROM user WHERE uid = me()
OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me())

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.

$fql = "select [...] from user where uid=123213312 OR uid=129038823 OR uid=893423890

But in this case your FQL query gets larger and larger so that you have to be divide it. Therefore use first solution.

究竟谁懂我的在乎 2024-11-14 03:47:22

每个 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.

半暖夏伤 2024-11-14 03:47:22

如果您不想使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文