Turns out, I was testing it using a test user which had no friends. That was the reason why the response was an empty array.
Facebook api call in php returns empty
-
12-07-2023 - |
Question
I have result of $result = $facebook->api($params);
How to extract information from it? Cant decode it using json_decode, gets an error the parameter is string. Searched a lot for the solution, couldn't find any related information.
EDIT
$params = array(
'method' => 'fql.query',
'query' => "SELECT uid,pic_square,name,devices FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())",
);
$result = $facebook->api($params);
Could this return empty? Without showing any error? What am I doing wrong?
Solution 2
OTHER TIPS
A simple debugging technique is to var_dump the variables to see where you're going wrong like so.
echo '<pre>'; //just to make the var_dump pretty in the browser
var_dump([variable you want to look into]);
exit(); //does let anything after it display
Assuming $params
is formatted correctly, I would try applying the var_dump to $result
after the code you just submitted. Then you'll see the format of the string is and hopefully why you aren't able to decode it. The above is a great debugging technique in general.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow