【发布时间】:2017-04-17 04:30:15
【问题描述】:
是我做错了什么,还是我们在 LiveStream API 中有错误?三个不同的来源如何为同一个 Ingestion 显示三个不同的直播名称?
由于某种原因,插入的 LiveStream 对象带有响应 与 YouTube 网页不匹配。
这个问题的部分:
- 直播的 PHP 代码
- API 结果到 $liveStream
- 用于广播插入和绑定的 PHP 代码
- 对 $bindBroadcastResponse 的响应
- YouTube 直播 API 浏览器
- 回顾
- YouTube 页面中的结果不匹配
用于直播的 PHP 代码
$streamSnippet = new \Google_Service_YouTube_LiveStreamSnippet();
$streamSnippet->setTitle($cameraName);
$cdn = new \Google_Service_YouTube_CdnSettings();
$cdn->setFormat($cameraName);
$cdn->setIngestionType('rtmp');
$streamInsert = new \Google_Service_YouTube_LiveStream();
$streamInsert->setSnippet($streamSnippet);
$streamInsert->setCdn($cdn);
$streamInsert->setKind('youtube#liveStream');
$liveStream = $youtube->liveStreams->insert('snippet,cdn',$streamInsert, array());
API 结果到 $liveStream
Google_Service_YouTube_LiveStream Object
(
[cdnType:protected] => Google_Service_YouTube_CdnSettings
...
[etag] => "5C5HHOaBSHC5ZXfkrT4ZlRCi01A/lY9i12sOWOAkTwfchEAQUxEWdX8"
[id] => UOzxsX96_We6MrMTsP5RiA1480670405575117
[kind] => youtube#liveStream
...
[modelData:protected] => Array
(
...
[cdn] => Array
(
[format] => 1440p
[ingestionType] => rtmp
[ingestionInfo] => Array
(
[streamName] => 9zfr-ggd9-brtf-XXXX
[ingestionAddress] => rtmp://a.rtmp.youtube.com/live2
[backupIngestionAddress] => rtmp://b.rtmp.youtube.com/live2?backup=1
)
[resolution] => 1440p
[frameRate] => 30fps
)
)
...
)
用于广播插入和绑定的 PHP 代码
$broadcastInsert = new \Google_Service_YouTube_LiveBroadcast();
$broadcastInsert->setSnippet($broadcastSnippet);
$broadcastInsert->setStatus($status);
$broadcastInsert->setKind('youtube#liveBroadcast');
$broadcastsResponse = $youtube->liveBroadcasts->insert('snippet,status',$broadcastInsert, array());
$bindBroadcastResponse = $youtube->liveBroadcasts->bind($broadcastsResponse['id'],'id,contentDetails',array('streamId' => $liveStream['id'],));
对 $bindBroadcastResponse 的响应
Google_Service_YouTube_LiveBroadcast Object
(
...
[etag] => "5C5HHOaBSHC5ZXfkrT4ZlRCi01A/_2Jev_YmRlYUwMBX1ptq_Kp8uVs"
[id] => idd8f7dSLzk
[kind] => youtube#liveBroadcast
...
[modelData:protected] => Array
(
[contentDetails] => Array
(
[boundStreamId] => UOzxsX96_We6MrMTsP5RiA1480670405575117
...
)
)
)
YouTube LiveStream API Explorer
如果我稍后列出所有流,使用LiveStream API Explorer,见下图,我得到第三个不同的结果(见下面的代码)。
{
"kind": "youtube#liveStreamListResponse",
"etag": "\"5C5HHOaBSHC5ZXfkrT4ZlRCi01A/RGcoFd2XK9IZmX0hgw_pFxuaeC4\"",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#liveStream",
"etag": "\"5C5HHOaBSHC5ZXfkrT4ZlRCi01A/d-ptvs6HC_oItk2Kv2PtrovurCk\"",
"id": "UOzxsX96_We6MrMTsP5RiA1480670405575117",
"snippet": ...,
"cdn": {
"format": "1440p",
"ingestionType": "rtmp",
"ingestionInfo": {
"streamName": "1wzh-zjwb-b0fr-XXXX",
"ingestionAddress": "rtmp://a.rtmp.youtube.com/live2",
"backupIngestionAddress": "rtmp://b.rtmp.youtube.com/live2?backup=1"
},
"resolution": "1440p",
"frameRate": "30fps"
}
}
]
}
回顾
PHP-> Google_Service_YouTube_LiveBroadcast[id] => idd8f7dSLzk
PHP-> Google_Service_YouTube_LiveStream->modelData[cdn][ingestionInfo][streamName] => 9zfr-ggd9-brtf-XXXX
API Explorer -> items[0].cdn.ingestionInfo.streamName => "1wzh-zjwb-b0fr-XXXX"
与 YouTube 页面中的结果不匹配
【问题讨论】:
-
我知道这可能看起来类似于stackoverflow.com/questions/18235664/…,但事实并非如此。该线程是很久以前的,不再适用。那时的 API 是 v2,现在是 v3(我正在使用 v3 api)
-
刚刚在谷歌打开了一个缺陷:code.google.com/p/gdata-issues/issues/…
-
仍在发生......
标签: php youtube youtube-livestreaming-api