php YouTube API V3:在哪里可以找到每个“videoCategoryId”的列表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17698040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:17:32  来源:igfitidea点击:

YouTube API V3: Where can i find a list of each 'videoCategoryId'?

phpyoutubeyoutube-apigoogle-api

提问by Haroldo

I'm using the Youtube API V3 but can't find documentation for how to filter by category:

我正在使用 Youtube API V3,但找不到有关如何按类别过滤的文档:

Here's my code:

这是我的代码:

$results = $youtube->search->listSearch('id,snippet', array(
    'q' =>                  $_GET['q'],
    'maxResults' =>         20,
    'type' =>               'video'
    'videoCategoryId' =>    'what-do-i-put-here?',
));

I've been going through their documentation for an hour and can't seem to find any reference to how I find out what the various category's ids are. In my case I'm looking for the videoCategoryId for music....

我已经浏览了他们的文档一个小时,似乎找不到任何关于我如何找出各种类别的 id 的参考。就我而言,我正在寻找音乐的 videoCategoryId ....

回答by Alaa Sadik

Using YouTube API v3 video category id list by Dinesh Gowtham Prathap at https://gist.github.com/dgp/1b24bf2961521bd75d6c

使用 Dinesh Gowtham Prathap 在https://gist.github.com/dgp/1b24bf2961521bd75d6c上的 YouTube API v3 视频类别 ID 列表

1 - Film & Animation 
2 - Autos & Vehicles
10 - Music
15 - Pets & Animals
17 - Sports
18 - Short Movies
19 - Travel & Events
20 - Gaming
21 - Videoblogging
22 - People & Blogs
23 - Comedy
24 - Entertainment
25 - News & Politics
26 - Howto & Style
27 - Education
28 - Science & Technology
29 - Nonprofits & Activism
30 - Movies
31 - Anime/Animation
32 - Action/Adventure
33 - Classics
34 - Comedy
35 - Documentary
36 - Drama
37 - Family
38 - Foreign
39 - Horror
40 - Sci-Fi/Fantasy
41 - Thriller
42 - Shorts
43 - Shows
44 - Trailers

回答by jlmcdonald

Video categories are region specific -- that's why the category list service requires either a category ID or a region, but not both. This endpoint:

视频类别是特定于区域的——这就是类别列表服务需要类别 ID 或区域,而不是两者的原因。这个端点:

https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&regionCode={two-character-region}&key={YOUR_API_KEY}

https://www.googleapis.com/youtube/v3/videoCategories?part=snippet®ionCode={two-character-region}&key={YOUR_API_KEY}

will return all categories, along with their ids, for a given region. So as Ikai Lan pointed out in the comments, the ID for music is '10' in the US and, in fact, in all regions where this category is allowed; but there may be some regions where it isn't allowed, or some regions that aren't supported at all.

将返回给定区域的所有类别及其 ID。因此,正如 Ikai Lan 在评论中指出的那样,音乐的 ID 在美国是“10”,事实上,在所有允许使用此类别的地区;但可能有些地区是不允许的,或者有些地区根本不支持。

回答by Ben Simpson

At the bottom of: https://developers.google.com/youtube/v3/docs/videoCategories/listis a 'try it now' section.

https://developers.google.com/youtube/v3/docs/videoCategories/list的底部是“立即尝试”部分。

Put 'snippet' in the field labelled 'part' and add a region code, e.g. GB or US in the field labelled 'regionCode'.

在标记为“part”的字段中放置“snippet”并在标记为“regionCode”的字段中添加区域代码,例如GB 或US。

This will bring back a full list of categories for your chosen region.

这将带回您所选地区的完整类别列表。