dongxie2613 2014-04-17 18:59
浏览 26
已采纳

使用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'];

Why does this not return anything?

  • 写回答

2条回答 默认 最新

  • du7133 2014-04-17 19:06
    关注

    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'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?