2013-07-05 67 views
1

我正在開發使用youtube API進行直播的代碼。我做了什麼無法獲得RTMP URL和流密鑰

  1. 我已經註冊了一個項目谷歌,並得到CLIENT_ID,client_secret和 的開發者ID
  2. 我做的OAuth 2.0,並得到該代碼,並將其交換到AUTH_TOKEN
  3. 我可以創建通過張貼域gdata.youtube.com

與請求現場活動

/feeds/api/users/default/live/events 

與頭

Authorization: Bearer AUTH_TOKEN 
GData-Version: 2 
Content-Type: application/atom+xml 
X-GData-Key: key=DEV_ID 

與內容

<?xml version='1.0' encoding='UTF-8'?> 
<entry xmlns='http://www.w3.org/2005/Atom' 
    xmlns:media='http://search.yahoo.com/mrss/' 
    xmlns:yt='http://gdata.youtube.com/schemas/2007'> 
    <title>Test</title> 
    <summary>Test gogogogo!</summary> 
    <content type='application/atom+xml'> 
    <entry> 
     <yt:private/> 
     <yt:cdn name='primary'> 
     <media:content yt:format='18'/> 
     <media:content yt:format='19'/> 
     </yt:cdn> 
    </entry> 
    </content> 
    <yt:when start='2013-07-05T22:00:00.000Z'/> 
</entry> 

這將返回HTTP代碼:201,我的現場活動被創建,但返回的數據 不包括流密鑰和RTMP URL。我需要這些數據自動啓動我的活動 事件。

返回數據

<?xml version='1.0' encoding='UTF-8'?> 
<entry xmlns='http://www.w3.org/2005/Atom' 
    xmlns:app='http://www.w3.org/2007/app' 
    xmlns:media='http://search.yahoo.com/mrss/' 
    xmlns:gd='http://schemas.google.com/g/2005' 
    xmlns:yt='http://gdata.youtube.com/schemas/2007' 
    gd:etag='W/&quot;CkEHR347eCp7I2A9WhFQEE0.&quot;'> 
    <id>tag:youtube.com,2008:live:event:XXXXXXXXXXXXXXXXXXXX</id> 
    <published>2013-07-05T05:03:56.000Z</published> 
    <updated>2013-07-05T05:03:56.000Z</updated> 
    <app:edited>2013-07-05T05:03:56.000Z</app:edited> 
    <category scheme='http://schemas.google.com/g/2005#kind' 
    term='http://gdata.youtube.com/schemas/2007#liveEvent'/> 
    <title>Test</title> 
    <summary>Test gogogogo!</summary> 
    <content type='application/atom+xml' 
    src='http://gdata.youtube.com/feeds/api/users/XXXXXXX/live/videos/XXXXXXXXX'/> 
    <link rel='self' type='application/atom+xml' 
    href='http://gdata.youtube.com/feeds/api/users/XXXXXXXXXXXXXXX/live/events/XXXXXXXXXXXXXXXXXX'/> 
    <link rel='edit' type='application/atom+xml' 
    href='http://gdata.youtube.com/feeds/api/users/XXXXXX/live/events/XXXXXXXXXXXXXXXXXXXXXX'/> 
    <author> 
    <name>XXXXXX</name> 
    <uri>http://gdata.youtube.com/feeds/api/users/XXXXXXXXXX</uri> 
    <yt:userId>XXXXXXXXXXXXX</yt:userId> 
    </author> 
    <media:group> 
    <media:description type='plain'>Test gogogogo!</media:description> 
    <media:title type='plain'>Test</media:title> 
    </media:group> 
    <yt:status>pending</yt:status> 
    <yt:when start='2013-07-05T22:00:00.000Z'/> 
</entry> 

如果我手動登錄YouTube,點擊我的創建現場活動,我可以看到我 流密鑰和RTMP URL那裏。我可以用它們手動開始流式傳輸 所以我的問題是:如何自動獲取STREAM KEY和RTMP URL(通過API 請求)?

---- ----編輯

基於https://developers.google.com/youtube/2.0/developers_guide_protocol_managing_live_events

它說,當我成功創建/添加事件,YouTube將返回URL這樣

<yt:cdn name='primary'> 
    <media:content yt:format='19' yt:name='yt-live_SpQXZYILnN0_35' 
     url='rtmp://rtmp1.youtube.com/videolive?...'/> 
    </yt:cdn> 

但在我的情況下,我退回的數據不包括這一行

回答

4

做了一些研究後,我通過發送這個請求來解決它

/feeds/api/users/default/live/events?inline=true 

和YouTube返回我RTMP服務器URL

感謝所有