2016-07-30 132 views
0

我偶然發現了YouTube liveStream API的意外行爲。YouTube liveStreaming API方法LiveStream.list不返回YouTube建議的流

每當我請求liveStream.list方法,我回來的唯一流是由我的編碼軟件或liveStream.insert調用發起的。

我試圖找回反而是在 默認編碼器設置提出了YouTube的視頻流:

enter image description here

難道我做錯了什麼?

+0

看來這是不可能的。通過閱讀這個[SO線程](http://stackoverflow.com/questions/33798901/youtube-api-v3-get-live-now-rtmp-and-streamkey),還沒有辦法做到這一點呢。 但是,您可以嘗試手動設置liveBroadcast和liveStream對象,將它們與liveBroadcasts.bind綁定,測試您的流並使用status.streamStatus過渡到liveStream對象上 – noogui

回答

1

可以檢索有關默認通過傳遞持續廣播類型參數liveBroadcast.list廣播信息,或「立即直播」。

0

下面是這個我最後的完整代碼,$api_stream_url包含ServerURL/StreamKey

listLiveBroadcasts持續 - 僅僅返回持久的廣播。

listLiveStreamsCDN - formatrtmpstreamNameingestionAddress

try { 

    // Execute an API request that lists broadcasts owned by the user who 
    // authorized the request. 
    $broadcastsResponse = $youtube->liveBroadcasts->listLiveBroadcasts(
     'id,snippet,contentDetails', 
     array(
      'broadcastType' => 'persistent', 
      'mine' => 'true', 
     )); 

    $boundStreamId = $broadcastsResponse['items']['0']['contentDetails']['boundStreamId']; 

    $streamsResponse = $youtube->liveStreams->listLiveStreams('id,snippet,cdn', array(
//   'mine' => 'true', 
     'id' => $boundStreamId 
    )); 


    /** 
    * 
    * (
    [format] => 720p 
    [ingestionType] => rtmp 
    [ingestionInfo] => Array 
    (
    [streamName] => 4vem-9233-mz3y-detq 
    [ingestionAddress] => rtmp://a.rtmp.youtube.com/live2 
    [backupIngestionAddress] => rtmp://b.rtmp.youtube.com/live2?backup=1 
    ) 

    [resolution] => 720p 
    [frameRate] => 30fps 
    ) 
    */ 
    $ingestionInfo = $streamsResponse['items']['0']['cdn']['ingestionInfo']; 

    /** 
    * (
    [publishedAt] => 2016-06-08T12:58:38.000Z 
    [channelId] => UCcdDtElpr9XM5MA1stpK 
    [title] => Default Stream 
    [description] => 
    [isDefaultStream] => 1 
    ) 
    */ 
    $broadcastsResponse = $streamsResponse['items']['0']['snippet']; 


    $api_stream_key = $ingestionInfo->streamName; 
    $api_stream_address = $ingestionInfo->ingestionAddress; 

    /** 
    * Example: 
    * rtmp://a.rtmp.youtube.com/live2/4vem-9233-mz3y-detq 
    */ 
    $api_stream_url = $api_stream_address."/".$api_stream_key; 


    return false; 

} catch (Google_Service_Exception $e) { 
    $htmlBody = sprintf('<p>A service error occurred: <code>%s</code></p>', 
     htmlspecialchars($e->getMessage())); 
} catch (Google_Exception $e) { 
    $htmlBody = sprintf('<p>An client error occurred: <code>%s</code></p>', 
     htmlspecialchars($e->getMessage())); 
}