用PHP解码Facebook API JSON

用PHP解码Facebook API JSON,php,json,facebook,api,decode,Php,Json,Facebook,Api,Decode,为什么不返回任何内容?json\u decode不适用于URL,它需要字符串作为参数。您必须获取此请求的响应并将其传递给json\u decode。大概是这样的: $url = 'https://api.facebook.com/method/links.getStats?urls=http://google.com&format=json'; $get = json_decode($url, true); echo 'Shares:' . $get['share_count']; 您

为什么不返回任何内容?

json\u decode
不适用于URL,它需要
字符串作为参数。您必须获取此请求的响应并将其传递给
json\u decode
。大概是这样的:

$url = 'https://api.facebook.com/method/links.getStats?urls=http://google.com&format=json';
$get = json_decode($url, true);
echo 'Shares:' . $get['share_count'];

您可以使用以下代码获得总计数

$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'];
$facebook\u count将给出facebook的总份额


谢谢

json\u decode
不适用于URL。您必须下载此请求的响应并将其传递给
json\u decode
$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;