Youtube API 视频列表返回的结果少于指示的结果 [英] Youtube API video list returns less results than indicated

查看:26
本文介绍了Youtube API 视频列表返回的结果少于指示的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自己的 YouTube 频道上运行查询以检索所有视频标题.我有 680 个视频,但只能获得其中的一半.我所做的是创建一个代码,该代码自创建频道以来迭代所有年份,并在一年内使用 pageTokens 浏览 50 个视频包.

I am running a query on my own youtube channel to retrieve all the video titles. I have 680 videos but can only get about half of them. What I have done is create a code that iterates all the years since creation of the channel and within a year uses the pageTokens to go through the packs of 50 videos.

因此查询将如下所示:

https://www.googleapis.com/youtube/v3/search?key={XXXXX}&channelId={XXXXX}&part=snippet,id&order=date&type=video&maxResults=50&publishedAfter=2018-01-01T00:00:00Z&publishedBefore=2019-01-01T00:00:00Z&pageToken=CDIQAA

在这些查询的结果中,我得到以下内容的指示:

In the results for these queries, I get the indication that there are the following contents:

array (
'totalResults' => 321,
'resultsPerPage' => 50,
),

遍历页面,我得到 2 个页面,其中包含 50 个项目,然后另一个页面也显示结果 'resultsPerPage' =>50, 但只包含 35 个视频,那一年的其余部分在 JSON 数据中有 0 个项目".所以有问题的页面只返回 135 个结果而不是 321 个.一旦我切换到下一年,我再次得到 2 页完整的结果,然后是一些缺失的,然后是空的.

Iterating through the pages, I get 2 pages filled with 50 items, then another one where the results show as well 'resultsPerPage' => 50, but contains only 35 videos, the rest for that year have 0 "items" in the JSON data. So the pages in question only give 135 results back instead of the 321. Once I switch to the next year, I get again 2 pages of full results, then one with some missing and then empty ones.

知道哪里出了问题吗?

这里是最后一个 JSON 数据集的摘录:

here is an excerpt of the last JSON data set:

array (
  'kind' => 'youtube#searchListResponse',
  'etag' => '"XpPGQXPnxQJhLgs6enD_n8JR4Qk/IsJyhRyDQ6qMmAHldktSRzEN2qs"',
  'nextPageToken' => 'CJYBEAA',
  'prevPageToken' => 'CGQQAQ',
  'regionCode' => 'DE',
  'pageInfo' => 
  array (
    'totalResults' => 321,
    'resultsPerPage' => 50,
  ),
  'items' => 
  array (
    0 => 
    [..contents..]
   35 =>
    [..last content and closing brackets..]

推荐答案

如果你想得到一个给定频道的整个视频列表而没有任何遗漏,我建议你使用 PlaylistItems 端点,通过将适当的值传递给端点的 playlistId 参数.

If you want to get the entire video list of a given channel without any omissions, I suggest you to use PlaylistItems endpoint instead, queried for the given channel's uploads list by passing a proper value to the endpoint's playlistId parameter.

在查询频道自己的端点.所需的 ID 可在 .items 中找到.contentDetails.relatedPlaylists.uploads.通常,频道 ID 与其对应的上传播放列表 ID 通过 s/^UC([0-9a-zA-Z_-]{22})$/UU\1/ 相关联.

A given channel's uploads playlistId is obtained upon querying the channel's own endpoint. The needed ID is to be found at .items.contentDetails.relatedPlaylists.uploads. Usually, an channel ID and its corresponding uploads playlist ID are related by s/^UC([0-9a-zA-Z_-]{22})$/UU\1/.

再说明一点:您应该注意差异 视频的发布时间和上传时间之间.

One more remark: your should be aware of the difference between a video's published time and upload time.

这篇关于Youtube API 视频列表返回的结果少于指示的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆