我们需要YouTube的频道名称的视频列表(使用API)。

我们可以通过下面的API获得一个频道列表(只有频道名):

https://gdata.youtube.com/feeds/api/channels?v=2&q=tendulkar

下面是频道的直接链接

https://www.youtube.com/channel/UCqAEtEr0A0Eo2IVcuWBfB9g

Or

WWW.YouTube.com/channel/HC-8jgBP-4rlI

现在,我们需要>> UCqAEtEr0A0Eo2IVcuWBfB9g或HC-8jgBP-4rlI频道的视频。

我们尝试

https://gdata.youtube.com/feeds/api/videos?v=2&uploader=partner&User=UC7Xayrf2k0NZiz3S04WuDNQ https://gdata.youtube.com/feeds/api/videos?v=2&uploader=partner&q=UC7Xayrf2k0NZiz3S04WuDNQ

但是,这并没有帮助。

我们需要把所有视频发到频道上。上传到一个频道的视频可以来自多个用户,因此我不认为提供用户参数会有帮助…


当前回答

首先,你需要从用户/频道获取代表上传的播放列表的ID:

https://developers.google.com/youtube/v3/docs/channels/list#try-it

您可以使用forUsername={username}参数指定用户名,或者使用mine=true来获得自己的用户名(您需要先进行身份验证)。Include part=contentDetails查看播放列表。

GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername=jambrose42&key={YOUR_API_KEY}

结果“relatedPlaylists”将包括“likes”和“uploads”播放列表。抓取“上传”播放列表ID。

还要注意,上传播放列表id是你的channelId,前缀是UU而不是UC。

接下来,获取播放列表中的视频列表:

https://developers.google.com/youtube/v3/docs/playlistItems/list#try-it

只需要输入playlistId!

GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=50&playlistId=UUpRmvjdu3ixew5ahydZ67uA&key={YOUR_API_KEY}

其他回答

试着像下面这样做。它可能对你有帮助。

https://gdata.youtube.com/feeds/api/videos?author=cnn&v=2&orderby=updated&alt=jsonc&q=news

在这里作者,你可以指定你的频道名称和“q”,因为你可以给你的搜索关键字。

使用已弃用的API版本2,用于上传的URL(通道UCqAEtEr0A0Eo2IVcuWBfB9g)是:

https://gdata.youtube.com/feeds/users/UCqAEtEr0A0Eo2IVcuWBfB9g/uploads

有一个API版本3。

最近,我不得不从一个频道检索所有视频,根据YouTube开发者文档: https://developers.google.com/youtube/v3/docs/playlistItems/list

function playlistItemsListByPlaylistId($service, $part, $params) {
    $params = array_filter($params);
    $response = $service->playlistItems->listPlaylistItems(
        $part,
        $params
    );

    print_r($response);
}

playlistItemsListByPlaylistId($service,
    'snippet,contentDetails',
    array('maxResults' => 25, 'playlistId' => 'id of "uploads" playlist'));

$service是Google_Service_YouTube对象。

因此,您必须从频道获取信息以检索“uploads”播放列表,该列表实际上包含该频道上传的所有视频:https://developers.google.com/youtube/v3/docs/channels/list

如果这个API是新的,我强烈建议将代码样例从默认代码片段转换为完整的样例。

因此,从一个频道检索所有视频的基本代码可以是:

class YouTube
{
    const       DEV_KEY = 'YOUR_DEVELOPPER_KEY';
    private     $client;
    private     $youtube;
    private     $lastChannel;

    public function __construct()
    {
        $this->client = new Google_Client();
        $this->client->setDeveloperKey(self::DEV_KEY);
        $this->youtube = new Google_Service_YouTube($this->client);
        $this->lastChannel = false;
    }

    public function getChannelInfoFromName($channel_name)
    {
        if ($this->lastChannel && $this->lastChannel['modelData']['items'][0]['snippet']['title'] == $channel_name)
        {
            return $this->lastChannel;
        }
        $this->lastChannel = $this->youtube->channels->listChannels('snippet, contentDetails, statistics', array(
            'forUsername' => $channel_name,
        ));
        return ($this->lastChannel);
    }

    public function getVideosFromChannelName($channel_name, $max_result = 5)
    {
        $this->getChannelInfoFromName($channel_name);
        $params = [
            'playlistId' => $this->lastChannel['modelData']['items'][0]['contentDetails']['relatedPlaylists']['uploads'],
            'maxResults'=> $max_result,
        ];
        return ($this->youtube->playlistItems->listPlaylistItems('snippet,contentDetails', $params));
    }
}

$yt = new YouTube();
echo '<pre>' . print_r($yt->getVideosFromChannelName('CHANNEL_NAME'), true) . '</pre>';

首先,你需要从用户/频道获取代表上传的播放列表的ID:

https://developers.google.com/youtube/v3/docs/channels/list#try-it

您可以使用forUsername={username}参数指定用户名,或者使用mine=true来获得自己的用户名(您需要先进行身份验证)。Include part=contentDetails查看播放列表。

GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername=jambrose42&key={YOUR_API_KEY}

结果“relatedPlaylists”将包括“likes”和“uploads”播放列表。抓取“上传”播放列表ID。

还要注意,上传播放列表id是你的channelId,前缀是UU而不是UC。

接下来,获取播放列表中的视频列表:

https://developers.google.com/youtube/v3/docs/playlistItems/list#try-it

只需要输入playlistId!

GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=50&playlistId=UUpRmvjdu3ixew5ahydZ67uA&key={YOUR_API_KEY}

只需三步:

订阅:list -> https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&maxResults=50&mine=true&access_token= {oauth_token} 通道:list -> https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id= {channel_id}关键= {YOUR_API_KEY} PlaylistItems: list -> https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId= {playlist_id}关键= {YOUR_API_KEY}