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'];
爲什麼這不會返回任何內容?使用PHP解碼Facebook API JSON
$url = 'https://api.facebook.com/method/links.getStats?urls=http://google.com&format=json';
$get = json_decode($url, true);
echo 'Shares:' . $get['share_count'];
爲什麼這不會返回任何內容?使用PHP解碼Facebook API JSON
json_decode
不適用於URL,它期望string
作爲參數。您必須獲取此請求的回覆並將其傳遞到json_decode
。類似這樣的:
$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'];
您可以通過使用以下代碼來獲得總計數。
$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將給出facebook的總份額。
謝謝
'json_decode'不適用於URL。你必須下載這個請求的響應並把它傳遞給'json_decode' – hindmost