YouTube API returning wrong result counts

北城余情 提交于 2019-12-25 05:30:49

问题


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:


First, get the ID for your uploads playlist:

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

The ID should be under 'uploads'.

Then, you can use the playlistItems list method:

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

and get the number of videos from totalResults.

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



来源:https://stackoverflow.com/questions/31140083/youtube-api-returning-wrong-result-counts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!