【问题标题】:YouTube liveStreaming API method LiveStream.list doesn't return stream proposed by YouTubeYouTube liveStreaming API 方法 LiveStream.list 不返回 YouTube 建议的流
【发布时间】:2016-12-05 05:12:11
【问题描述】:

我偶然发现了YouTube liveStream API 的意外行为。

每当我请求liveStream.list 方法时,我返回的唯一流是由我的编码软件或liveStream.insert 调用发起的流。

我试图检索的是 YouTube 在 默认编码器设置:

我做错了吗?

【问题讨论】:

  • 看来这是不可能的。通读这个SO thread,还没有办法做到这一点。但是,您可以尝试手动设置 liveBroadcast 和 liveStream 对象,将它们与 liveBroadcasts.bind 绑定,测试您的流,并使用 status.streamStatus 过渡到 liveStream 对象
  • 一个broadcast(又名事件)必须有一个stream(尽管数据可能稍后会出现),问题是你在broadcast页面上,所以YouTube会自动生成stream.

标签: youtube youtube-api youtube-data-api


【解决方案1】:

您可以通过为liveBroadcast.list 中的broadcastType 参数传递persistent 来检索有关默认广播或“立即流式传输”广播的信息。

【讨论】:

    【解决方案2】:

    这是我的最终完整代码$api_stream_url 包含 ServerURL/StreamKey

    listLiveBroadcasts persistent – 仅返回持久广播。

    listLiveStreams cdn - format, rtmp, streamName, ingestionAddress

    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()));
    }
    

    【讨论】:

      猜你喜欢
      • 2014-09-03
      • 1970-01-01
      • 2019-09-20
      • 2014-02-06
      • 2013-07-12
      • 2018-11-03
      • 1970-01-01
      • 2014-07-09
      • 2016-01-27
      相关资源
      最近更新 更多