PHP - YouTube Live API - 获取视频ID



我想做的是获取当前在YouTube上播放的所有直播视频的列表,并嵌入它们,或者如果不可能,至少链接到它们可用的YouTube。

使用 Zend 框架检索提要的代码非常简单。

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

printVideoEntry() 只显示一堆关于该视频的数据。它适用于频道或播放列表提要。当它用于实时流时,不存在大量数据。这只是标题、描述和作者。我想要的是视频的视频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

返回空值。

有人能帮我解决这个问题吗?谢谢!

你能var_dump整个对象吗?这似乎不是PHP问题,而是Zend Framework特有的问题。(此外,放置zend-framework标签应该为您的问题提供更好的结果)

最新更新