views:

166

answers:

1

Hi , 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  A: 

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();
Sarfraz
Thanks Sarfraz. That really helped !However, the query results are not displayed. Infact If I put an echo statement before echo $result, nothing is printed. This might as well be just a php issue, I am not sure what might be wrong there.P.S: 1] I see the auth_token continuous changing with new values and page being refreshed as if it is looping over something:http://aaaaa.facebook.joyent.us?auth_token=abe83bc9b2eee58c38edaa2ccce1ec682] The query returns an array. I also tried print_r($result). I read dat array is a map in php, however I dont know key here to print a particular value
p1