图api(facebook)太慢了 [英] Graph api (facebook) is too slow

查看:98
本文介绍了图api(facebook)太慢了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Graph API进行简单的操作时,例如:

While I'm using the Graph API to simple action, like this for example:

require 'src/facebook.php';

# facebook class
$facebook = new Facebook(array(
  'appId'  => 'XXX',
  'secret' => 'XXX',
));

for ($i = 0; $i < 9; $i++)
{
    $url = $facebook->api('/Intel');
    echo $url['name'] . '<br />';
}

(只是一个快速的例子,我想返回9个不同的页面,现在很重要)

(just a quick example, I want to return 9 different pages but it doesn't matter now)

嗯,这个动作花了9 - 10秒!太多了..这是页面上唯一的acion(你可以尝试运行它看看)。

Well, this action took 9 - 10 SECONDS! too much.. and this is the only acion on the page (you can try run it and see).

我该怎么办? (如果我使用FQL通过api [作为方法fql.query]它不会改善运行时间,我检查了)我必须使用图形API。

What can I do? (if I'm using FQL via api [as method fql.query] it doesn't improve the running time, I checked it) I have to using graph api.

顺便说一下,我使用PHP SDK 3.0.1(最新版本..也许这是问题?)

By the way, I'm using PHP SDK 3.0.1 (newest version.. maybe this is the problem?)

推荐答案

我建议你在这里使用FQL并批量发送多个查询。这样你就可以进行一个远程调用并获取多个查询的数据。

Do you realize that you are making a remote call in a loop? It will make several remote calls one by one, thats why its slow. API is damn fast. What I would suggest you is to use FQL here and send multiple queries in batch. This way you make one remote call and get data of several queries together.

/**
 * FQL multiquery
 */
$multiquery_fql[ 'query1' ] = $query1;
$multiquery_fql[ 'query2' ] = $query2;
$multiquery_fql = json_encode( $multiquery_fql );
$multiquery_result = $facebook->api(array(
    "method"    => "fql.multiquery",
    "queries"     => $multiquery_fql,
    'access_token' => '' // fill a generic token here (granted to app, independent of user)
));

我总是建议使用一个应用程序。更好地让您的应用程序阻止,以防万一出现问题,而不是IP。

And I would always recommend using an app. Its better to get your app blocked in case something goes wrong instead of IP.

这篇关于图api(facebook)太慢了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆