YouTube liveStreaming API 方法 LiveStream.list 不 return 流 YouTube 提议
YouTube liveStreaming API method LiveStream.list doesn't return stream proposed by YouTube
我偶然发现了 YouTube liveStream API 的意外行为。
每当我请求 liveStream.list
方法时,我返回的唯一流是由我的编码软件或 liveStream.insert
调用启动的流。
我要检索的是 YouTube 在
默认编码器设置:
我是不是做错了什么?
您可以通过为 broadcastType 参数传递 persistent 来检索有关默认或 "Stream Now" 广播的信息10=].
这是我最终的完整代码,$api_stream_url
包含ServerURL/StreamKey
listLiveBroadcasts 持久 – Return 仅持续广播。
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()));
}
我偶然发现了 YouTube liveStream API 的意外行为。
每当我请求 liveStream.list
方法时,我返回的唯一流是由我的编码软件或 liveStream.insert
调用启动的流。
我要检索的是 YouTube 在 默认编码器设置:
我是不是做错了什么?
您可以通过为 broadcastType 参数传递 persistent 来检索有关默认或 "Stream Now" 广播的信息10=].
这是我最终的完整代码,$api_stream_url
包含ServerURL/StreamKey
listLiveBroadcasts 持久 – Return 仅持续广播。
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()));
}