Search code examples
phpfacebookfacebook-fqlfacebook-php-sdk

Using FQL with Facebook SDK for PHP v5


I'd like to make the following FQL query using the latest Facebook SDK for PHP, is there a way to do it ?

SELECT like_count, share_count, comment_count FROM link_stat WHERE url="http://stackoverflow.com"

I tried to find answers or tutorials using Google and SO, but they all seem to refer to SDK for PHP prior to v5.

How do I do that ?

And while I'm at it : what is the maximum number of queries I can do in a given time ?

Thanks

(NB : I know FQL is deprecated and will be down in about a year, but as far as I know, there is no way to achieve what I want with the Graph API.)


Solution

  • There is a way to achieve this using Graph API, see URL Lookup. Please read the doc.

    Below code should work (not tested):

    $node = $fb->get('/?id='urlencode($url).'&fields=og_object,share'])->getGraphNode();
    
    $likeCount = $node['og_object']['engagement']['count'];
    $shareCount = $node['share']['share_count'];
    $commentCount = $node['share']['comment_count'];