我正在使用 YouTube php 流 API 来监视某些流的状态,并在尝试获取“lastUpdateTimeSeconds”时返回 null。我已经完成了从准备到完成的整个流式传输过程(认为它可能不会在你上线之前更新)并且从未收到除 NULL 之外的任何内容。
我有以下代码获取每个广播及其相关流的详细信息,并仔细检查了代码。
$broadcastsResponse = $youtube->liveBroadcasts->listLiveBroadcasts('id,snippet,status,contentDetails',
array(
'mine' => 'true',
'maxResults' => '10',
));
$streamsResponse = $youtube->liveStreams->listLiveStreams('id,snippet,status',
array(
'mine' => 'true',
'maxResults' => '10',
));
foreach ($broadcastsResponse['items'] as $broadcastItem) {
$program = new stdClass();
$program->broadcast = new stdClass();
$program->broadcast->id = $broadcastItem['id'];
$program->broadcast->title = $broadcastItem['snippet']['title'];
$program->broadcast->lifeCycleStatus = $broadcastItem['status']['lifeCycleStatus'];
$program->broadcast->recordingStatus = $broadcastItem['status']['recordingStatus'];
$program->broadcast->boundStreamId = $broadcastItem['contentDetails']['boundStreamId'];
$program->broadcast->enableMonitorStream = $broadcastItem['contentDetails']['monitorStream']['enableMonitorStream'];
$program->stream = new stdClass();
$program->stream->id = false;
$program->stream->title = "";
$program->stream->streamStatus = "";
$program->stream->healthStatus = "";
$program->stream->lastUpdate = "";
foreach($streamsResponse['items'] as $streamItem)
{
if ($streamItem['id'] == $program->broadcast->boundStreamId)
{
$program->stream->id = $streamItem['id'];
$program->stream->title = $streamItem['snippet']['title'];
$program->stream->streamStatus = $streamItem['status']['streamStatus'];
$program->stream->healthStatus = $streamItem['status']['healthStatus']['status'];
$program->stream->lastUpdate = $streamItem['status']['healthStatus']['lastUpdateTimeSeconds'];
break;
}
}
$json->data[] = $program;
}
一切似乎都有效,除了$program->stream->lastUpdate = $streamItem['status']['healthStatus']['lastUpdateTimeSeconds'];
文档声明它应该返回一个 unix 时间戳,但我不能让它这样做。