2012-09-15 185 views
0

我想要做的是獲取當前在YouTube上播放的所有實時視頻的列表,並嵌入它們,或者如果不可能,則至少鏈接到它們提供的YouTube。PHP - YouTube Live API - 獲取視頻ID

使用Zend框架檢索提要的代碼非常簡單。

$videoFeed = $yt->getVideoFeed('https://gdata.youtube.com/feeds/api/charts/live/events/live_now'); 
    foreach ($videoFeed as $videoEntry) { 
     printVideoEntry($videoEntry); 
    } 

而printVideoEntry()只顯示一堆關於該視頻的數據。它適用於頻道或播放列表Feed。當它用於直播時,很多數據不存在。這只是標題,描述和作者。我想要的是視頻的視頻ID。

通過請求提要的網址,我得到了一個xml的提要。以下是一個示例視頻條目。

<entry gd:etag='W/&quot;CUYEQ347eCp7I2A9WhJUFks.&quot;'> 
<id>tag:youtube.com,2008:live:event:IKv8FeyLmiIl-8iUVVahpRaYMLRCD0xt</id> 
<published>2012-09-14T21:14:31.000Z</published> 
<updated>2012-09-14T22:51:42.000Z</updated> 
<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#liveEvent'/> 
<title>TGIFF Live Stream with Realm (League of Legends)</title> 
<summary>Realm's Livestream: Thank God it's Freakin Friday! This week we're getting into some League of Legends action and teaching our ambitious Hundar how to play! This live show will air every Friday from 4-6pm PST on http://www.machinimalive.com 
Subscribe to the Machinima Live newsletter here! http://eepurl.com/o1-kP</summary> 

<content type='application/atom+xml' src='https://gdata.youtube.com/feeds/api/users/MachinimaRealm/live/videos/YbeDQJ_FSVA?v=2'/> 
<link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/VEbcFWM43PS-d5vaSKUMng/live/events/IKv8FeyLmiIl-8iUVVahpRaYMLRCD0xt?v=2'/> 
<author><name>MachinimaRealm</name><uri>https://gdata.youtube.com/feeds/api/users/MachinimaRealm</uri><yt:userId>VEbcFWM43PS-d5vaSKUMng</yt:userId></author> 

<media:group><media:description type='plain'>Realm's Livestream: Thank God it's Freakin Friday! This week we're getting into some League of Legends action and teaching our ambitious Hundar how to play! This live show will air every Friday from 4-6pm PST on http://www.machinimalive.com 
Subscribe to the Machinima Live newsletter here! http://eepurl.com/o1-kP</media:description><media:title type='plain'>TGIFF Live Stream with Realm (League of Legends)</media:title></media:group><yt:status>active</yt:status><yt:when end='2012-09-15T01:00:00.000Z' start='2012-09-14T22:51:42.000Z'/></entry> 

「內容」項目包含的視頻ID爲'src',但我不知道如何訪問它。

echo $videoEntry->content->src 

返回null。

有人能幫我解決這個問題嗎?謝謝!

回答

0

你能var_dump整個對象?它看起來並不像PHP問題,而是一個Zend Framework的特定問題。 (另外,把zend-framework標籤應該爲你的問題提供更好的結果)

+0

謝謝,儘管var_dumping對象從Zend產生了很多數據,它變得很難導航。 (Zend_Gdata_YouTube_VideoEntry)#30(38){[「_entryClassName:protected」] => string(29)「Zend_Gdata_YouTube_VideoEntry」[「_noEmbed:protected」] => NULL [「_statistics:protected」 ] => NULL [「_racy:protected」] => NULL [「_rating:protected」] => NULL [「_rating:protected」] => NULL [「_feed:protected」 ] => array(0){} [「_where:protected」] => NULL [「_recorded:protected」] => NULL [「_location:protected」] => NULL 我想要的數據嵌套在那裏。 –