Youtube REST API v3 - include statistics for video in search query result

荒凉一梦 提交于 2019-12-21 07:34:57

问题


I want to perform search queries using Youtube API v3. What I need is to retrieve video ids and statistics for each video. From the docs I can see that statistics is not returned for video items. If I try to ask for statistics using this query:

https://www.googleapis.com/youtube/v3/search?type=video&part=snippet,statistics&q=kittens&key={MY_KEY}

I receive an error:

{
 "error": {
  "errors": [
   {
    "domain": "youtube.part",
    "reason": "unknownPart",
    "message": "statistics",
    "locationType": "parameter",
    "location": "part"
   }
  ],
  "code": 400,
  "message": "statistics"
 }
}

So I guess that I need to make two requests:

  1. Perform actual search and retrieve list of video ids.
  2. Make API request https://developers.google.com/youtube/v3/docs/videos/list to retrieve statistics for each video.

Or maybe I'm missing something and there's a way to get statistics for videos within one search query?


回答1:


In the guide, they specify "the part names that you can include in the parameter value are id and snippet" when using https://www.googleapis.com/youtube/v3/search. (statistics is not an accepted value).

So I think that you have to make two requests as you say, at least that is what I'm doing. I couldn't find any other solution. I would be interested to know if there was a workaround...




回答2:


To avoid redundancy of data returned and not to use bandwidth with extra data, "video search data" and "video statistics" data are decoupled in API. You are right about two calls. In general, to get faster response, only use the "part" s in request that you will use in your application.



来源:https://stackoverflow.com/questions/14836838/youtube-rest-api-v3-include-statistics-for-video-in-search-query-result

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