YouTube API 返回错误的结果计数 [英] YouTube API returning wrong result counts

查看:32
本文介绍了YouTube API 返回错误的结果计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 http://gdata.youtube.com/feeds/api/videos?author=[channel]&start-index=[index] 上的旧供稿不再可用,我不得不切换到官方 YouTube API 来获取频道上所有视频的列表.但是,我遇到了这个 API 没有在频道上返回正确视频计数的问题.这也导致无法使用 pageToken,因为没有返回.

Since the old feed on http://gdata.youtube.com/feeds/api/videos?author=[channel]&start-index=[index] is no longer available, I had to switch to the official YouTube API to get a list of all videos present on a channel. However, I've ran into the issue that this API does not return the right videocount on a channel. This also leads to being unable to use the pageToken, as none is returned.

预期的结果是总共有 159 个视频,但是,在大约 50% 的情况下,API 告诉我只有 16 个视频.

The expected result is to have a an amount of 159 videos in total, however, at around 50% the API tells me there are only 16 videos.

我正在使用以下网址:

https://www.googleapis.com/youtube/v3/search?key=*****&channelId=UCsuBLfTDK4Hjn9Q6AYPwGqQ&part=snippet,id&order=date&maxResults=25

由于 16 低于每个请求的最大结果数量,所以我有一半的时间不需要 nextPageToken 来分页并获取每条记录的列表,这使得该 API 在生产中完全无用..

As 16 is lower than the max amount of results per request, I wont have a nextPageToken half of the time which I need to paginate and get a list of every record, making this API completely useless in production..

我能做些什么来解决这个问题,还是 YouTube 方面的问题?或者还有什么我可以用作替代品的吗?我只需要某个频道上每个视频的视频 ID.

Is there anything I can do to resolve this issue, or is this a problem that lies on the YouTube side? Or is there anything else I can use as an alternative? All I need is the video IDs of every video on a certain channel.

推荐答案

首先,获取上传播放列表的 ID:

First, get the ID for your uploads playlist:

GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=CHANNEL_ID&key=API_KEY

ID 应该在 'uploads' 下.

然后,您可以使用 playlistItems list 方法:

Then, you can use the playlistItems list method:

GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=PLAYLIST_ID&key=API_KEY

并从 totalResults 中获取视频数量.

and get the number of videos from totalResults.

或者,您可以使用 playlistItems 文档获取已上传视频的列表.

Alternatively, you can use the code from the playlistItems documentation to get a list of the uploaded videos.

这篇关于YouTube API 返回错误的结果计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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