0
$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?

1
  • json_decode doesn't work with URLs. You have to download response of this request and pass it to json_decode Commented Apr 17, 2014 at 19:03

2 Answers 2

2

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'];
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.