开发者

Graph api (facebook) is too slow

开发者 https://www.devze.com 2023-03-14 01:10 出处:网络
While I\'m using the Graph API to simple action, like this for example: require \'src/facebook.php\'; # facebook class

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 />';
}

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

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).

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

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


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)
));

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


for this part of the graph api you dont need the api, so dont use it. just fetch http://graph.facebook.com/Intel via curl and json_decode it.

or if you can use it

$data = json_decode(file_get_contents('http://graph.facebook.com/Intel'));
0

精彩评论

暂无评论...
验证码 换一张
取 消