YouTube API - 从单个视频中获取频道详情

时间:2017-11-14 23:19:47

标签: php api youtube channel

我试图通过他们的API使用php以及来自频道的详细信息从YouTube上的单个视频获取频道详细信息。

我的代码:

private function getYoutubePosts(){
    $timelines = array();

    for ($a = 0; $a < count($this->youtube_sources['users']); ++$a) {

        //ChannelId
        $channelId = false;
        if (strlen($this->youtube_sources['users'][$a]) == '24') {
            $channelId = $this->youtube_sources['users'][$a];
        } else {
            //Get the channelId
            $channel_info = $this->curlCall('https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername='.$this->youtube_sources['users'][$a].'&maxResults=1&fields=items%2Fid&key='.$this->youtube_sources['app_secret']);
            $channelId = $channel_info->items[0]->id;
        }
        //Videos
        if ($channelId) {
            $user_posts = $this->curlCall('https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&order=date&channelId='.$channelId.'&key='.$this->youtube_sources['app_secret']);
            if (isset($user_posts->items)) {
                array_push($timelines, $user_posts->items);

            }
        }  
    }

    return $timelines;

获取数据。我应该修改什么,所以我也可以获得频道缩略图?

    for ($i = 0; $i < count($youtube_timelines); ++$i) {
            $timeline = $youtube_timelines[$i];
            if ($a < count($timeline)) {
                $post = $timeline[$a];
                array_push($blended_timelines, array(
                        'source' => 'youtube',
                        'username' => $post->snippet->channelTitle,
                        'id' => $post->id->videoId,
                        'link' => 'https://www.youtube.com/watch?v='.$post->id->videoId,
                        'timestamp' => (int) strtotime($post->snippet->publishedAt),
                        'created_time' => date('d M Y', strtotime($post->snippet->publishedAt)),
                        'text' => $post->snippet->description,
                        'image' => $post->snippet->thumbnails->high->url,

                        'author_picture' => $???,



                        )

已阅读https://developers.google.com/youtube/v3/docs/videos/list&amp; https://developers.google.com/youtube/v3/docs/channels/list几次。

我想获得channelId缩略图&#34;显示。我会想念或忽略某些事情吗?

0 个答案:

没有答案