YouTube API returning wrong result counts

时间:2015-06-30 13:48:23

标签: youtube youtube-api

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.

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.

I'm using the following url:

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

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..

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.

1 个答案:

答案 0 :(得分:3)

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

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

ID应位于'uploads'

之下

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

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

并从totalResults获取视频数量。

或者,您可以使用playlistItems documentation中的代码 获取上传视频的列表。