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

但是,这并没有帮助。

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


当前回答

你需要看看YouTube数据API。您将在那里找到关于如何访问API的文档。您还可以找到客户端库。

你也可以自己提出要求。下面是一个从频道检索最新视频的示例URL:

https://www.googleapis.com/youtube/v3/search?key={your_key_here}&channelId={channel_id_here}&part=snippet,id&order=date&maxResults=20

之后,你会收到一个包含视频id和详细信息的JSON,你可以像这样构建你的视频URL:

http://www.youtube.com/watch?v={video_id_here}

其他回答

你需要看看YouTube数据API。您将在那里找到关于如何访问API的文档。您还可以找到客户端库。

你也可以自己提出要求。下面是一个从频道检索最新视频的示例URL:

https://www.googleapis.com/youtube/v3/search?key={your_key_here}&channelId={channel_id_here}&part=snippet,id&order=date&maxResults=20

之后,你会收到一个包含视频id和详细信息的JSON,你可以像这样构建你的视频URL:

http://www.youtube.com/watch?v={video_id_here}

从https://stackoverflow.com/a/65440501/2585501:

如果a)该频道有超过50个视频,或者b)希望将youtube视频id格式化为平面txt列表,则此方法特别有用:

Obtain a Youtube API v3 key (see https://stackoverflow.com/a/65440324/2585501) Obtain the Youtube Channel ID of the channel (see https://stackoverflow.com/a/16326307/2585501) Obtain the Uploads Playlist ID of the channel: https://www.googleapis.com/youtube/v3/channels?id={channel Id}&key={API key}&part=contentDetails (based on https://www.youtube.com/watch?v=RjUlmco7v2M) Install youtube-dl (e.g. pip3 install --upgrade youtube-dl or sudo apt-get install youtube-dl) Download the Uploads Playlist using youtube-dl: youtube-dl -j --flat-playlist "https://<yourYoutubePlaylist>" | jq -r '.id' | sed 's_^_https://youtu.be/_' > videoList.txt (see https://superuser.com/questions/1341684/youtube-dl-how-download-only-the-playlist-not-the-files-therein)

Python中的示例解决方案。从这个视频中得到帮助:视频 与许多其他答案一样,上传id首先从通道id中检索。

import urllib.request
import json

key = "YOUR_YOUTUBE_API_v3_BROWSER_KEY"

#List of channels : mention if you are pasting channel id or username - "id" or "forUsername"
ytids = [["bbcnews","forUsername"],["UCjq4pjKj9X4W9i7UnYShpVg","id"]]

newstitles = []
for ytid,ytparam in ytids:
    urld = "https://www.googleapis.com/youtube/v3/channels?part=contentDetails&"+ytparam+"="+ytid+"&key="+key
    with urllib.request.urlopen(urld) as url:
        datad = json.loads(url.read())
    uploadsdet = datad['items']
    #get upload id from channel id
    uploadid = uploadsdet[0]['contentDetails']['relatedPlaylists']['uploads']

    #retrieve list
    urld = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=50&playlistId="+uploadid+"&key="+key
    with urllib.request.urlopen(urld) as url:
        datad = json.loads(url.read())

    for data in datad['items']:
        ntitle =  data['snippet']['title']
        nlink = data['contentDetails']['videoId']
        newstitles.append([nlink,ntitle])

for link,title in newstitles:
    print(link, title)

使用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

获取频道列表:

通过forUserName获取频道列表:

https://www.googleapis.com/youtube/v3/channels?part=snippet,contentDetails,statistics&forUsername=Apple&key=

按频道id获取频道列表:

https://www.googleapis.com/youtube/v3/channels/?part=snippet,contentDetails,statistics&id=UCE_M8A5yxnLfW0KghEeajjw&key=

获取通道部分:

https://www.googleapis.com/youtube/v3/channelSections?part=snippet,contentDetails&channelId=UCE_M8A5yxnLfW0KghEeajjw&key=

获取播放列表:

按频道ID获取播放列表:

https://www.googleapis.com/youtube/v3/playlists?part=snippet,contentDetails&channelId=UCq-Fj5jknLsUf-MWSy4_brA&maxResults=50&key=

使用pageToken通过频道ID获取播放列表:

https://www.googleapis.com/youtube/v3/playlists?part=snippet,contentDetails&channelId=UCq-Fj5jknLsUf-MWSy4_brA&maxResults=50&key=&pageToken=CDIQAA

获取PlaylistItems:

通过PlayListId获取PlaylistItems列表:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,contentDetails&maxResults=25&playlistId=PLHFlHpPjgk70Yv3kxQvkDEO5n5tMQia5I&key=

获取视频:

通过视频id获取视频列表:

https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails,statistics&id=YxLCwfA1cLw&key=

通过多个视频id获取视频列表:

https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails,statistics&id=YxLCwfA1cLw,Qgy6LaO3SB0,7yPJXGO2Dcw&key=

获取评论列表

按视频ID获取评论列表:

https://www.googleapis.com/youtube/v3/commentThreads?part=snippet replies&videoId = el * * * * kQak&key = ********** k

按频道ID获取评论列表:

https://www.googleapis.com/youtube/v3/commentThreads?part=snippet replies&channelId = U * * * * * q键= AI * * * * * * * * k

通过allThreadsRelatedToChannelId获取评论列表:

https://www.googleapis.com/youtube/v3/commentThreads?part=snippet replies&allThreadsRelatedToChannelId =加州大学* * * * * ntcQ&key = AI * * * * * k

这里所有的api都是Get方法。

基于频道id,我们不能直接得到所有的视频,这是这里的重点。

对于集成https://developers.google.com/youtube/v3/quickstart/ios?ver=swift