LiveStream有不同的"流名称"从LiveStream API PHP创建时(已检查的API结果,使用API​​ Explorer和YouTube页面)

时间:2016-12-02 09:52:07

标签: php youtube youtube-livestreaming-api

我做错了什么,或者我们在LiveStream API中有错误?三个不同的来源如何为同一个摄取显示三个不同的实时流名称?

由于某种原因,插入的LiveStream对象带有响应 与YouTube网页不匹配。

这个问题的部分:

  • 直播的PHP代码
  • API结果到$ liveStream
  • 用于广播插入的PHP代码&结合
  • 响应$ bindBroadcastResponse
  • YouTube LiveStream API Explorer
  • 小结
  • 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资源管理器

如果我稍后使用LiveStream API Explorer列出所有流,请参阅下面的图片,我得到了第三个不同的结果(请参阅下面的代码)。

enter image description here

{
 "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页面中的结果与

不匹配

LiveStream id does not match the one I got from creation

1 个答案:

答案 0 :(得分:0)

非常很长一段时间后,有人回复了我填写给Google的错误。

这是来自this thread的回复:

  

不一定要求API提供的流密钥   匹配用户界面提供的流密钥。但是,如果   两个流密钥是不同的,两者都应该有效。

     

如果您在流中遇到问题,请回复此错误   键是不同的,只有其中一个有效。

事情是,我之前尝试过使用我从API获得的流名称,但它没有用。

立即测试,它有效。