0

My idea is to implement something like this:

https://i.stack.imgur.com/8BmW5.png

screenshot is from here: http://www.thedrum.co.uk/opinion/2012/03/08/five-ways-new-facebook-timeline-will-impact-brands

I've read that I have to use either Facebook graph API or FQL but I don't know which one is the best.

This is what I have so far but it takes a long to do it so my guess is that is the wrong method:

      <? require_once 'libs/facebook.php';

      // Create our Application instance.
      $facebook = new Facebook(array(
        'appId' => 'appid',
        'secret' => 'secret',
        'cookie' => true,
      ));

      $result = $facebook->api(array(
      'method' => 'fql.query',
      'query' => 'SELECT share_count, like_count, comment_count, total_count FROM link_stat WHERE url="URL";'
      ));
      echo '<p>'.$result[0]['like_count'].' likes';
      ?>

Is it OK if I try to get the share count (using one of the methods mentioned before) of let's say 50 different posts I have on my home page? Doesn't Facebook have a limit for this?

dythffvrb
  • 177
  • 1
  • 9

1 Answers1

0

Use the graph API. FQL still works but it isn't one of Facebook's priorities.

Here is the link so you can see how it works: https://developers.facebook.com/docs/reference/api/

Secondly buffer the number so you aren't hitting Facebook everytime and will get faster page loads on your end.

Adam
  • 16,089
  • 6
  • 66
  • 109
  • Thanks for your answer. This is what I've in order to retriev the share count from Facebook using the graph API: http://pastebin.com/U9GRiqvH It's still slow. is it normal? Can you tell me how to cache the results? – dythffvrb Mar 11 '12 at 07:10
  • I wouldn't ever assume the Graph API to be always 100% responsive so I would always code around that fact. Store the number in your database and either set it to update when someone clicks on the like or at an interval. Pull the number from your DB. Memcache your result from your DB to increase speed. – Adam Mar 11 '12 at 08:21