YouTube Streaming API lastUpdateTimeSeconds返回NULL

时间:2016-02-22 13:41:12

标签: php youtube youtube-livestreaming-api

我正在使用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时间戳,但我不能这样做。

0 个答案:

没有答案