python-3.x 如何在YouTube Data API V3中获取视频类别?

oprakyz7  于 2022-12-20  发布在  Python
关注(0)|答案(1)|浏览(140)

我想得到一些类别的视频。但我找不到它的文档。
我得到的视频ID和标题如下:

resp = requests.get('https://www.googleapis.com/youtube/v3/search', 
                    params= {
                        "key":"My Key",
                        "part":"snippet",
                        "q":"IT",
                        "maxResults":1,
                        "order":"rating",
                        "regionCode":"KR"
                        }

我找了两个小时都没找到。对不起,我的英语很差,要花很长时间才能习惯

jdzmm42g

jdzmm42g1#

您必须向videos:list端点发出另一个请求才能获取视频详细信息。
这是一个example
样品结果- * 简化 *:

"items": [
    {
      "kind": "youtube#video",
      "etag": "RL6[...]",
      "id": "ouf0ozwnU84",
      "snippet": {
        "publishedAt": "2022-02-25T23:00:16Z",
        "channelId": "UCYzHwra_yDr-QGFiopiOPnw",
        "title": "Cards to Consider: Blindly Loyal Goblin [...]",
        "description": "#Shorts\nWhy is Blindly Loyal Goblin Interesting?[...].",
        "thumbnails": {
          "default": {
            "url": "https://i.ytimg.com/vi/ouf0ozwnU84/default.jpg"
          }
        },
        "channelTitle": "TCGTheory",
        "tags": [
          "TCGTheory",
          "Card Game Analysis",
          "Yu-gi-oh!",
          [...]
        ],
        "categoryId": "20", // <= Video category "Gaming".
      }
    }
]

在本例中,categoryId是20 - Gaming。
您可以检查视频类别here

相关问题