Reputation: 45
$url = 'https://api.facebook.com/method/links.getStats?urls=http://google.com&format=json';
$get = json_decode($url, true);
echo 'Shares:' . $get['share_count'];
Why does this not return anything?
Upvotes: 0
Views: 705
Reputation: 561
You can get the total count by using the following code.
$url = $this->get_json_values( 'https://api.facebook.com/method/links.getStats?urls=http://google.com&format=json' );
$json = json_decode( $url, true );
$facebook_count = isset( $json[0]['share_count'] ) ? intval( $json[0]['share_count'] ) : 0;
$facebook_count will give the total share count for facebook.
Thanks
Upvotes: 0
Reputation: 7195
json_decode
doesn't work with URLs, it expects string
as parameter. You have to fetch response of this request and pass it to json_decode
. Something like this:
$url = 'https://api.facebook.com/method/links.getStats?urls=http://google.com&format=json';
$get = json_decode(file_get_contents($url), true);
echo 'Shares:' . $get['share_count'];
Upvotes: 2