首页 > 解决方案 > 没有通过 Google_Service_YouTube 进行直播(google/apiclient)

问题描述

我正在尝试将 YouTube(视频和直播)整合到我们的媒体网站中。我正在使用,基于 PHP,google/apiclient:^2.0

到目前为止,我通过 OAuth 成功完成了身份验证和授权,并检索了已在我的 Google/Youtube 用户的相应频道中上传的点播视频列表。即使在不重复强制登录的情况下管理离线访问也有效。

尽管如此,检索当前的直播流,而且我必须强调该流是活跃的并且可以在 Youtube 的仪表板中观看,是行不通的。直播源通过 Wowza 4.7 推送到 Youtube,运行完美。

这是负责获取数据的代码片段:

public function livestreams()
    {
        try {
            $this->_loadToken();

            $this->setService(new \Google_Service_YouTube($this->getClient()));

            $streamsResponse = $this->getService()->liveStreams->listLiveStreams('id,snippet', array(
                'mine' => 'true',
            ));


        } catch (\Exception $e) {
            \Log::error($e->getMessage());
            return [];
        }
        return $streamsResponse;
    }

此查询的结果:

Google_Service_YouTube_LiveStreamListResponse {#416 ▼
  #collection_key: "items"
  +etag: ""XXXXXXXX""
  +eventId: null
  #itemsType: "Google_Service_YouTube_LiveStream"
  #itemsDataType: "array"
  +kind: "youtube#liveStreamListResponse"
  +nextPageToken: null
  #pageInfoType: "Google_Service_YouTube_PageInfo"
  #pageInfoDataType: ""
  +prevPageToken: null
  #tokenPaginationType: "Google_Service_YouTube_TokenPagination"
  #tokenPaginationDataType: ""
  +visitorId: null
  #internal_gapi_mappings: []
  #modelData: []
  #processed: []
  +"pageInfo": Google_Service_YouTube_PageInfo {#417 ▶}
  +"items": []
}

所以items是空的,而我希望能找到一个项目,即我推送到 YouTube 的当前活跃且可观看的直播流。

这是 API 中的一个缺陷,还是我这边存在根本性的误解?

标签: phpyoutube-apigoogle-api-php-clientyoutube-livestreaming-api

解决方案


推荐阅读