How To Use FQL With The Facebook PHP SDK

Foreword

So the other day while building a Facebook application, I needed to get some information that I just couldn’t find any way to get other than through the use of FQL  Needless to say, finding examples of FQL are plentiful.  However, examples that use FQL and the Facebook PHP SDK are not.  So I thought I’d put one together.

Getting Started

If you haven’t already done so, make sure you’ve installed the latest Facebook SDK and registered your Facebook application.

FQL And The Facebook SDK

Here’s an example call to get all the photos that belong to the logged in user:

$appInfo = array(
'appId' => 'XXXXXXXXXXXXX',
'appSecret' => 'XXXXXXXXXXXXXXXXXXXXX'
); 
 
$facebook = new Facebook($appInfo);
 
$result = $facebook->api( array('method' => 'fql.query', 'query' => 'SELECT src, caption FROM photo WHERE owner=me()') );
foreach($result as $photo){
   ...
}

And there you have it. Hopefully this will save someone the amount of time it took for me to figure it out.

One thought on “How To Use FQL With The Facebook PHP SDK

  1. MK

    It did!!! I’d already put far too many hours in by the time I found your site. Thank you! Sincerely this was awesome of you. There is so little published on FQL that actually presents it in context.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *