Gublooo
Gublooo

Reputation: 2618

Facebook graph getting my likes takes 75 seconds or longer

On my profile page, I'm trying to pull all my likes from facebook and display the detail about each like. For example, if I like the tv show Seinfeld, I will display the Seinfeld logo along with how many like it etc.

I'm using the php sdk and it takes forever to pull the data.

Currently I have only 24 likes and it takes 75 seconds to pull this data.

This is the code I am using

<pre>
$likes = $facebook->api('/me/likes');

foreach($likes['data'] as $like) {

$like_item = $facebook->api($like['id']);
?>
<fb:profile-pic uid="&lt;?php echo $like_item['id'];?>" size="square"></fb:profile-pic> 
<?php 
echo $like_item['name'];
?>
<fb:like href="<?php echo $like_item['link'];?>"></fb:like> 
<?
}

</pre>

Any idea why its taking so long. Am I doin it the right way or is there a better way to approach this. Thanks a bunch

Upvotes: 1

Views: 508

Answers (2)

Yuliy
Yuliy

Reputation: 17728

You should be able to do $facebook->api('/me/likes?fields=id,name,link') to fetch all of the needed data in one pass.

Upvotes: 2

Mike Sherov
Mike Sherov

Reputation: 13427

Yeah, there is a much better approach than this! Basically, you're making an additional API call for EACH like. If you like 75 things, you're making 76 API calls, each of which could take a second. Instead of iterating over ‘$likes‘, do:

$likes_csv = implode(',',$likes['data']);
$likes_items = $facebook->API('/?ids='.$likes_csv);

Then you can do what you want with ‘$likes_items‘

Upvotes: 2

Related Questions