我们需要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

但是,这并没有帮助。

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


当前回答

使用gapi JavaScript API可以做到这一点

<script src="https://apis.google.com/js/api.js"></script>
const start = () => {
  gapi.client
    .init({
      apiKey: "your_youtubeApiKey",
      discoveryDocs: ["https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest"],
      scope: "https://www.googleapis.com/auth/youtube.readonly",
    })
    .then(() => {
      console.log("gapi.client initiated");
    })
    .then(() =>
      gapi.client.youtube.channels.list({
        part: "snippet,contentDetails,statistics",
        id: "youtube_channelId",
        // forUsername: 'Bankless',
      })
    )
    .then(
      (res) =>
        // get the youtube related playlist id
        res.result.items[0].contentDetails.relatedPlaylists.uploads
    )
    .then((playlistId) =>
      gapi.client.youtube.playlistItems.list({
        part: "snippet",
        playlistId,
        maxResults: 50,
      })
    )
    .then((res) =>
      // get youtube videos snippets
      res.result.items.map((item) => item.snippet)
    )
    .then((snippets) =>
      snippets.map((snippet) => {
        const { title, description, resourceId } = snippet;
        const { videoId } = resourceId;
        return { title, description, videoId };
      })
    )
    .then((videos) => {
      console.log(videos);
    })
    .catch((err) => console.error(err));
};
gapi.load("client", start);

文档:

https://github.com/google/google-api-javascript-client https://developers.google.com/youtube/v3/guides/auth/client-side-web-apps#callinganapi

其他回答

下面是返回频道下所有视频id的代码

<?php 
    $baseUrl = 'https://www.googleapis.com/youtube/v3/';
    // https://developers.google.com/youtube/v3/getting-started
    $apiKey = 'API_KEY';
    // If you don't know the channel ID see below
    $channelId = 'CHANNEL_ID';

    $params = [
        'id'=> $channelId,
        'part'=> 'contentDetails',
        'key'=> $apiKey
    ];
    $url = $baseUrl . 'channels?' . http_build_query($params);
    $json = json_decode(file_get_contents($url), true);

    $playlist = $json['items'][0]['contentDetails']['relatedPlaylists']['uploads'];

    $params = [
        'part'=> 'snippet',
        'playlistId' => $playlist,
        'maxResults'=> '50',
        'key'=> $apiKey
    ];
    $url = $baseUrl . 'playlistItems?' . http_build_query($params);
    $json = json_decode(file_get_contents($url), true);

    $videos = [];
    foreach($json['items'] as $video)
        $videos[] = $video['snippet']['resourceId']['videoId'];

    while(isset($json['nextPageToken'])){
        $nextUrl = $url . '&pageToken=' . $json['nextPageToken'];
        $json = json_decode(file_get_contents($nextUrl), true);
        foreach($json['items'] as $video)
            $videos[] = $video['snippet']['resourceId']['videoId'];
    }
    print_r($videos);

注意:你可以在 登录https://www.youtube.com/account_advanced。

你必须获得你想要从中获取数据的视频的channel_id。

为了通过video_id获得channel_id,你可以使用YouTube数据API的videos:list端点-在Id参数中添加video_id。的例子。

然后,使用channel_id,将第二个字符更改为“U”:

这个修改后的id是上传播放列表说YouTube频道。

有了这个Uploads playlist_id,你可以使用YouTube数据API的Playlistitem:list端点从频道检索所有上传的视频。

在部分参数中添加“id,snippet,contentDetails,status”。 并在playlistID中添加修改后的通道ID。 然后执行。

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

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

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

只需三步:

订阅: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}

下面是一个来自谷歌开发者的视频,展示了如何在YouTube API的v3中列出一个频道中的所有视频。

有两个步骤:

查询Channels以获得“uploads”Id。例如https://www.googleapis.com/youtube/v3/channels?id={channel Id}&key={API key}&part=contentDetails 使用这个“uploads”Id查询PlaylistItems以获得视频列表。例如https://www.googleapis.com/youtube/v3/playlistItems?playlistId={"uploads" Id}&key={API key}&part=snippet&maxResults=50