问题
I am trying to run a FQL for the first time. This is the code I have included in my index.php file:
<?php $query="SELECT message FROM status WHERE uid = 544337058";echo $query; ?>
<?php
include_once ('facebook.php');
$api_key = 'XXXXXXXXXXXXXXX';
$secret = 'XXXXXXXXXXXXXXXXX';
global $facebook;
$facebook = new Facebook($api_key, $secret);
$result = $facebook->api_client->fql_query($query);
?>
<?php echo $result?>
I have logged into facebook from a different tab and just trying to read my own status message. However I am getting the following error:
SELECT message FROM status WHERE uid = @@@@@@
Fatal error: Uncaught exception 'FacebookRestClientException' with message 'Requires
user session' in /users/home/aafhe7vh/web/public/facebookapi_php5_restlib.php:3065 Stack
trace: #0 /users/home/aafhe7vh/web/public/facebookapi_php5_restlib.php(1025):
FacebookRestClient->call_method('facebook.fql.qu...', Array) #1 /users/home/aafhe7vh
/web/public/status.php(46): FacebookRestClient->fql_query('SELECT message ...') #2 {main}
thrown in /users/home/aafhe7vh/web/public/facebookapi_php5_restlib.php on line 3065
How do I get and provide a user's session to this query.
Thanks.
回答1:
Try putting require_login
method after $facebook
object eg it should be like:
$facebook = new Facebook($api_key, $secret);
$facebook = $facebook->require_login();
If it is facebook application which it seems to be, also put this line below require_login
:
$facebook = $facebook->require_frame();
来源:https://stackoverflow.com/questions/3081206/problem-while-executing-facebook-query