I have this code:
<?php
$fql = "SELECT url, normalized_url, share_count, like_count, comment_count, ";
$fql .= "total_count, commentsbox_count, comments_fbid, click_count FROM ";
$fql .= "link_stat WHERE url = 'http://apple.com'";
$apifql = "https://api.facebook.com/method/fql.query?format=json&query=".urlencode($fql);
$json = file_get_contents($apifql);
$obj = json_decode($json);
print_r($obj);
?>
that outputs:
Array ( [0] => stdClass Object ( [url] => http://apple.com [normalized_url] => http://www.apple.com/ [share_count] => 366493 [like_count] => 514795 [comment_count] => 298452 [total_count] => 1179740 [commentsbox_count] => 0 [comments_fbid] => 381975869314 [click_count] => 16558 ) )
How can I define into a string only the commentsbox_count? I need it for my database.
You can access it through
$obj[0]->commentsbox_count.The top-level element is a one-element array with the only key being
0. This element is a stdClass object (which is pretty much like an array but with properties instead of array elements) so you access the element using->name.