Search code examples
phpfacebookfacebook-graph-apifacebook-fql

Facebook PHP-SDK or GET request on Graph API?


I am new to this field, and I would like to build a small external PHP application based on Facebook API and data from users.

I found that I can use the PHP-SDK
$results = $facebook->api('/fql', array('q'=>'FQL_QUERY'));
or a GET request to http://graph.facebook.com/fql?q=FQL_QUERY_HERE

What is the best method to use? Are there any difference in speed?
How can I make a GET request? using get file contents?


Solution

  • Facebook is committed to the Graph API being the future of their platform and to best future proof your app you will probably want to follow suit.

    I would recommend using the CURL functions in PHP to make your request as they are generally considered to be the fastest and most versatile.

    $c = curl_init("http://graph.facebook.com/1");
    
    // necessary so CURL doesn't dump the results on your page
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    
    $result = curl_exec($c);
    curl_close ($c);
    
    $facebookUser = json_decode($result);
    print_r($facebookUser);