开发者

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.

开发者_如何学C

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


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


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‘

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜