频道视频列表中缺少的视频

Videos missing from a channel's video list

我正在尝试检索有关给定 YouTube 频道的所有视频的信息。

这是我的第一个请求:

GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={CHANNEL_ID}&maxResults=50&type=video&key={YOUR_API_KEY}

{
  "kind": "youtube#searchListResponse",
  "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/15j9AlxbMtzBhzffpA04ahJgv9g\"",
  "nextPageToken": "CDIQAA",
  "regionCode": "FR",
  "pageInfo": {
    "totalResults": 375,
    "resultsPerPage": 50
  },
  "items": [
    "... 50 items here ..."
  ]
}

如您所见,共有 375 个结果。因此,使用 nextPageToken,我搜索了接下来的 50 个视频。

GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={CHANNEL_ID}&maxResults=50&pageToken=CDIQAA&type=video&key={YOUR_API_KEY}

{
  "kind": "youtube#searchListResponse",
  "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/7mmGfmqsGmfP8OggZWZVefQ7z6Q\"",
  "nextPageToken": "CGQQAA",
  "prevPageToken": "CDIQAQ",
  "regionCode": "FR",
  "pageInfo": {
    "totalResults": 375,
    "resultsPerPage": 50
  },
  "items": [
    "... 28 more items here ..."
  ]
}

此回复中只有 28 个项目。此外,如果我查询下一页:

GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={CHANNEL_ID}&maxResults=50&pageToken=CGQQAA&type=video&key={YOUR_API_KEY}

这一次,没有任何物品。

{
  "kind": "youtube#searchListResponse",
  "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/XKJQFk8Z_J6XraQ0mVCRtVWnSYc\"",
  "nextPageToken": "CJYBEAA",
  "prevPageToken": "CGQQAQ",
  "regionCode": "FR",
  "pageInfo": {
    "totalResults": 375,
    "resultsPerPage": 50
  },
  "items": [
  ]
}

是什么导致了这种行为?我的请求有问题吗?

YouTube Data API v3 你应该:

第 1 步:获取您频道的上传播放列表

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

json "kind": "youtube#channel", "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/8HOHPc1ZO5cOiePp8nFHwKA99HM\"", "id": "UCRVDPcrF_LTJo8u0bkzUL9A", "contentDetails": { "relatedPlaylists": { "uploads": "UURVDPcrF_LTJo8u0bkzUL9A", "watchHistory": "HL", "watchLater": "WL" 您频道的上传播放列表是UURVDPcrF_LTJo8u0bkzUL9A

第 2 步:使用 youtube.playlistItems.list 通过指定您频道的 uploads 播放列表

playlistId 来获取您频道中上传的所有视频

GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&pageToken={WHEN_YOU_HAVE_A_PAGETOKEN_PUT_IT_HERE}&playlistId=UURVDPcrF_LTJo8u0bkzUL9A&key={YOUR_API_KEY}


参考问题的答案:

  • youtube-api-v3-list-uploaded-videos
  • how-do-i-obtain-a-list-of-all-videos-in-a-channel-using-the-youtube-data-api-v3

关于 Search: list API

的行为

如此处所述:https://developers.google.com/youtube/v3/docs/search/list 关于搜索结果 属性 pageInfo.totalResults我按字面意思引用:

The total number of results in the result set.Please note that the value is an approximation and may not represent an exact value. In addition, the maximum value is 1,000,000.

You should not use this value to create pagination links. Instead, use the nextPageToken and prevPageToken property values to determine whether to show pagination links.

此外,通过一些调查,我进行了测试,结果中 "missing" 的视频似乎如您所指出的那样,但是,当显式指定可选参数 q 时,它们会出现在结果中在请求中指定,显然只有指定的过滤器值可以被相关视频的数据满足。