Need help to get more than 100 results using YouTube search API

こ雲淡風輕ζ 提交于 2019-11-29 15:37:16

问题


Is there some way I can retrieve more than 100 results using YouTube API?

I can retrive upto 100 results using this query string: https://gdata.youtube.com/feeds/api/videos?q=football&orderby=relevance&start-index=1&max-results=10&v=2

But when I try https://gdata.youtube.com/feeds/api/videos?q=football&orderby=relevance&start-index=101&max-results=10&v=2

I get: http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/"C0YFQHg9fyp7I2A9WhBVGUk."'>tag:youtube.com,2008:videos2013-04-26T01:51:51.667Zhttp://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>Videos matching: footballhttp://www.youtube.com/img/pic_youtubelogo_123x63.gifhttps://www.youtube.com'/>http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos?v=2'/>http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos/batch?v=2'/>https://gdata.youtube.com/feeds/api/videos?q=football&start-index=101&max-results=10&orderby=relevance&v=2'/>https://gdata.youtube.com/feeds/api/videos?alt=atom-service&v=2'/>https://gdata.youtube.com/feeds/api/videos?q=football&start-index=91&max-results=10&orderby=relevance&v=2'/>YouTubehttp://www.youtube.com/http://gdata.youtube.com'>YouTube data API10010110

From what I understand, you can get 999 results using YouTube search API. Why is this limited to 100 here? Is there a workaround for me to get more than 100 results?

Thanks!


回答1:


I can't speak to whether or not something has changed internally that is now capping totalResults at 100, but it seems to be a pretty common problem across the board today. However, if you were to try using v3 of the API, this wouldn't be an issue: for example, this query:

https://www.googleapis.com/youtube/v3/search?q=football&part=id&key=YOUR_DEVELOPER_KEY

Will give you many, many more total results. With v3, you can set the maxResults parameter up to 50 videos returned for each response, and then paginate through the responses by setting the pageToken parameter to whatever the "nextPageToken" attribute of a given response is.




回答2:


Try like this https://gdata.youtube.com/feeds/api/videos?q=football&orderby=relevance&v=2 It will take the default size. When you use the start index and size you are using the pagination mechanism. I guess thats the problem here. And misfortune is that Google youtube API supports only max of 50 videos per query. Its there in the docs. 999 videos are the total videos that can be in a video feed. Not the number of videos it would query out. Dont mistakenly take it as it would return you all the videos. You have to use pagination with start index and size inorder to go through all the videos.




回答3:


you can use this url

https://www.googleapis.com/youtube/v3/search?q=football&part=id&key=YOUR_DEVELOPER_KEY&max-results=150

and you easily get more than 100 results




回答4:


I'm confused by this same issue - video search queries with start-index > 100 do not return any results:

http://gdata.youtube.com/feeds/api/videos?v=2&q=skateboarding+dog&max-results=50&start-index=101

and queries with a start-index < 100 return only the number of videos up to 100:

http://gdata.youtube.com/feeds/api/videos?v=2&q=skateboarding+dog&max-results=50&start-index=90

gives you 10 videos.

Shouldn't you be able to access results beyond the first 100 returned by the search?




回答5:


There's a caching/escalating issue for pagination.

Check this answer here.

The correct way to page through a feed is to make the first request for the feed without a start-index, and then check to see whether there's a <link rel="next'...> and if so, use that URL to retrieve the next page of a feed.




回答6:


I discovered that if you put a small pause between each pagination call to API, it returns 400 results, it's mean 1 call per page putting 2 second between each call. It works for my. If you wuould like get more it, you have to close the connection to API and try again one or two minutes later.



来源:https://stackoverflow.com/questions/16227540/need-help-to-get-more-than-100-results-using-youtube-search-api

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