首页 文章

使用YouTube Data API V3按关键字搜索视频

提问于
浏览
0

我的目标是使用YouTube Data API v3搜索与输入关键字匹配的YouTube视频 . 现在,YouTube Data API v3允许您仅使用“q”参数搜索通过开发人员的应用程序或网站上传的视频,但它不允许您像在YouTube中一样搜索与输入搜索关键字匹配的视频应用 .

如果我错过了指南中的内容或者有一些解决方法可以实现这一点,请纠正我 .

1 回答

  • 0

    我自己制作了一个YouTube应用程序,以下链接对我有用:

    https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=20&q=YOURKEYWORD&type=video&key=YOURAPIKEY

    确保您拥有一个可以从Google免费获得的注册API密钥 . 服务器的答案将是JSON格式,您应该已经熟悉它 .

    现在返回一个包含20个条目的列表,每个条目代表一个YouTube视频,就像您在youtube.com上的搜索框中输入关键字一样 .

    “zoo”作为关键字和我的API-Key的示例:

    {
     "kind": "youtube#searchListResponse",
     "etag": "\"q5k97EMVGxODeKcDgp8gnMu79wM/EkP6ScMYfT4xPyx9BIwzJc1IcsM\"",
     "nextPageToken": "CBQQAA",
     "regionCode": "DE",
     "pageInfo": {
      "totalResults": 1000000,
      "resultsPerPage": 20
     },
     "items": [
      {
       "kind": "youtube#searchResult",
       "etag": "\"q5k97EMVGxODeKcDgp8gnMu79wM/gWwm8abtbKoWg-uMt7NUmwSLzbA\"",
       "id": {
        "kind": "youtube#video",
        "videoId": "iVIjckwltkk"
       },
       "snippet": {
        "publishedAt": "2014-02-25T18:22:56.000Z",
        "channelId": "UChl6CG-V7LgqhfwkvbHH67Q",
        "title": "Kids At The Zoo: Compilation",
        "description": "In this funny animal video, tune in to see an awesome compilation of kids interacting with their favorite animals at the zoo. SUBSCRIBE TO PETSAMI: ...",
        "thumbnails": {
         "default": {
          "url": "https://i.ytimg.com/vi/iVIjckwltkk/default.jpg",
          "width": 120,
          "height": 90
         },
         "medium": {
          "url": "https://i.ytimg.com/vi/iVIjckwltkk/mqdefault.jpg",
          "width": 320,
          "height": 180
         },
         "high": {
          "url": "https://i.ytimg.com/vi/iVIjckwltkk/hqdefault.jpg",
          "width": 480,
          "height": 360
         }
        },
        "channelTitle": "Kyoot Animals",
        "liveBroadcastContent": "none"
       }
      }, ... and so on
     ]
    }
    

相关问题