2013-06-26 15 views
0

鏈接在PHP數組的Facebook圖形API數據

http://graph.facebook.com/?id=http://givingmode.com/ 

給了我這個數據

{ 
    "id": "http://givingmode.com/", 
    "shares": 3 
} 

現在,我使用這個腳本來獲取ID,股價在PHP變量

$File= file_get_contents('http://graph.facebook.com/?id=http://givingmode.com/'); 
    $p=json_decode($File); 
    foreach ($p as $loc) 
    { 
     $fb_tot_share=$loc->shares; 
    } 

但我不知道我在做什麼錯;

我得到$fb_tot_share爲空白。

請幫我解決這個問題。

回答

0

也許用它這樣?

$fb_tot_share=$loc["shares"]; 
0

試試這個: -

var link = "http://givingmode.com"; 
jQuery.getJSON('http://graph.facebook.com/?ids=' + link, function (data) { 
    console.log("Shares : " +data[link].shares); 
}); 

或使用本: -

$File= file_get_contents('http://graph.facebook.com/?id=http://givingmode.com/'); 
    $p=json_decode($File); 
    $fb_tot_share=$p->shares; 

    echo $fb_tot_share; 


Output : 3 
0

試試這個:

<?php 
$File= file_get_contents('http://graph.facebook.com/?id=http://givingmode.com/'); 
$obj=json_decode($File); 
echo "Total shares: ".$obj->shares; 
?>