PHP Facebook FQL: Making queries in the new SDK

2019-04-13 07:46发布

问题:

New to PHP and Graph API.

It seems that in the old API you could create a facebook object and pass in a standard query (select blah in blank where x = y ...) but now I don't see how to do that. All of the examples in the facebook documentation have you using a get_file_contents for graph.facebook.com/?fql etc. I've been trying to use that but it seems inefficient for complex queries.

Help? I'm kinda confused and don't understand some of the facebook documentation.

Thanks.

回答1:

Using the PHP SDK you can run fql queries by :

$facebook = new Facebook(array(
       'appId'  => 'YOUR_API_KEY',
       'secret' => 'YOUR_API_SECRET',
       'cookie' => true,
));

 $fql = "Your query";

 $response = $facebook->api(array(
     'method' => 'fql.query',
     'query' =>$fql,
 ));

 print_r($response);

I’ve also seen it done this way as well:

$param  =   array(
      'method'    => 'fql.query',
      'access_token' => $cookie['access_token'],
      'query'     => $fql,
      'callback'  => ''
);
$response   =   $facebook->api($param);
print_r($response);

Hope this helps :)



回答2:

Try this, it's pretty elegant:

$param  =   array(
    'method'    => 'fql.query',
    'access_token' => $cookie['access_token'],
    'query'     => $fql,
    'callback'  => ''
);
$response   =   $facebook->api($param);
print_r($response);