2013-01-23 68 views
1

我在過去幾週一直致力於Facebook應用程序。我已經成功發佈數據到Facebook的Graph API,但我一直在努力找回特定的領域。我正在使用API​​瀏覽器來測試我的各種GET嘗試。下面是與API調用返回的數據的摘錄:我/ g_music:listen_to欄=數據Facebook圖形API - 從子字段獲取數據

{ 
    "data": [ 
{ 
    "data": { 
    "song": { 
     "id": "355308601243965", 
     "url": "https://g8-music.herokuapp.com/object/song.php?title=Pierce+The+Veil+-+Bulls+in+the+Bronx&description=Played+On+G8-Music+for+Windows+8.&image=http%3A%2F%2Fuserserve-ak.last.fm%2Fserve%2F174s%2F78366946.jpg", 
     "type": "g_music:song", 
     "title": "Pierce The Veil - Bulls in the Bronx" 
    } 
    }, 
    "id": "245964195537372" 
}, 
{ 
    "data": { 
    "song": { 
     "id": "365613963536278", 
     "url": "https://g8-music.herokuapp.com/object/song.php?title=Pierce+The+Veil+-+Kings+for+a+Day+%28feat.+Kellin+Quinn%29&description=Played+On+G8-Music+for+Windows+8.&image=http%3A%2F%2Fuserserve-ak.last.fm%2Fserve%2F174s%2F78366946.jpg", 
     "type": "g_music:song", 
     "title": "Pierce The Veil - Kings for a Day (feat. Kellin Quinn)" 
    } 
    }, 
    "id": "245961632204295" 
}, 

我試圖拿到冠軍的價值,但沒有成功爲止。

如果我嘗試類似:me/g_music:listen_to?fields = data.data ...我收到一個異常,告訴我「子字段不受數據支持」。

我對圖API比較陌生,所以我很可能缺少一些明顯的東西。

回答

1

你不會錯過任何東西。我通過Graph API Explorer驗證了這一點。

的子域不會被數據

支持,但你必須在整個數據,簡單地獲取從數組中標題

+0

感謝您的回覆。但是,我仍然在訪問數據時遇到問題。我可以使用'id'作爲鍵輕鬆訪問id字段,但如果我嘗試訪問標題,則不會返回任何值。這很可能是由於我缺乏PHP中數組的經驗。 ?我當前的代碼有云:

<?php echo he($ id); ?>

<?php } ?> 這工作正常,但如果我將'id'更改爲'title',則不會得到任何輸出。 –

+0

試試這個:'<?php foreach($ listetens ['data'] as $ listen){$ title = $ listen ['title']; $ id = $ listen ['id']}?>'。 –