Offline
Online
Viewers

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:

[codesyntax lang=”php”]

$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){
   ...
}

[/codesyntax]

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

1 Comment

  1. 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.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Affiliates