搜索视频并在单个请求中获取视频统计信息

搜索视频并在单个请求中获取视频统计信息

本文介绍了Youtube API 3.0 搜索视频并在单个请求中获取视频统计信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用 youtube api 3.0 搜索 youtube 视频.

I'm searching youtube videos with youtube api 3.0.

我正在使用这种类型的 API 请求示例

I'm using this type of example API request

https://www.googleapis.com/youtube/v3/search?part=snippet&key=[API_KEY]

但我想在同一个 api 请求中获取视频的统计信息.如何解决这个问题.

But i want to get statistics of videos with in the same api request. How to solve this problem.

注意:当我使用 statistics 键时.我出错了.

Note: When I'm using statistics key with part. I got error.

我也尝试过这个请求

https://www.googleapis.com/youtube/v3/search?part=snippet,statistics&key=[API_KEY]

推荐答案

资源search.list没有part statistics.

您需要使用 search.list 获取视频的 videoId:"videoId": "UHdgXkkVyl0".

You need to get the videoId of the video: "videoId": "UHdgXkkVyl0" with search.list.

请求:

https://www.googleapis.com/youtube/v3/search?part=id&q=tuto&type=video&key={YOUR_API_KEY}

回复:

 "items": [
  {
   "kind": "youtube#searchResult",
   "etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/34CzOO9FXYQg7kdlOeoe59LsWVk\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "UHdgXkkVyl0"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/U303dB0TgZ89ODlqdwuKs5efOdk\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "LvEA2KHWQec"
   }
  },

第 2 步:

使用search.list 搜索视频后,您需要使用资源video.list参数 :

Step 2 :

After you have searched videos with search.list you need to make a second call to the API with the resource video.list with parameters :

part: statistics
id: "id of the video found in previous request"

  • 如果您有多个视频 id,您可以使用逗号分隔列表指定视频的 id,例如:

    • If you have more than one video id you can specify the id of videos with a comma-separated list like :

      id: "Xxsdw6zG1bg, Xxsdw6zG1bg,...." )

      id: "Xxsdw6zG1bg, Xxsdw6zG1bg,...." )

      请求:https://www.googleapis.com/youtube/v3/videos?part=statistics&id=UHdgXkkVyl0%2C+Xxsdw6zG1bg&key={YOUR_API_KEY}

      响应如下:

      {
       "kind": "youtube#videoListResponse",
       "etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/rxvjZzq2nNqBg7Me5VQv1ToZm64\"",
       "pageInfo": {
        "totalResults": 2,
        "resultsPerPage": 2
       },
       "items": [
        {
      
         "kind": "youtube#video",
         "etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/3fah-cngFxFOnytseMYZU1TK_-8\"",
         "id": "UHdgXkkVyl0",
         "statistics": {
          "viewCount": "3070836",
          "likeCount": "72140",
          "dislikeCount": "1132",
          "favoriteCount": "0",
          "commentCount": "7798"
         }
        },
        {
      
         "kind": "youtube#video",
         "etag": "\"MmqJLb8ZBOWRQIsg7xej7lrKLMI/J4xM7Dd23TGYU6on-PESyEIAE9A\"",
         "id": "Xxsdw6zG1bg",
         "statistics": {
          "viewCount": "131487",
          "likeCount": "1459",
          "dislikeCount": "25",
          "favoriteCount": "0",
          "commentCount": "39"
         }
        }
       ]
      }
      

      你有统计数据!

      这篇关于Youtube API 3.0 搜索视频并在单个请求中获取视频统计信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

      1403页,肝出来的..

09-06 18:06