youtube api 仅音乐过滤器
youtube api music only filter
我正在尝试仅过滤带有 api 的音乐视频。
我在 youtube api(v3) 网站上看过,但找不到。
try {
// Call the search.list method to retrieve results matching the specified
// query term.
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_GET['q'],
'maxResults' => $_GET['maxResults'],
'type' => 'video',
**'videoCategoryId' => 'Music',**
));
music
的 videoCategoryID
是 10
。你可以在这里看到:
https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&id=10&key={YOUR_API_KEY}
所以你的代码最终看起来像这样:
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_GET['q'],
'maxResults' => $_GET['maxResults'],
'type' => 'video',
'videoCategoryId' => '10'
));
这是获取完整类别列表的快速而粗略的方法:
<?php
$ids = implode(",", range(1,50));
$JSON = file_get_contents("https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&id=" . $ids . "&key={YOUR-API-KEY}");
$json_data = json_decode($JSON, true);
foreach ($json_data['items'] as $category) {
echo $category['id'] . ' = ' . $category['snippet']['title'] . '<br/>';
}
?>
我正在尝试仅过滤带有 api 的音乐视频。
我在 youtube api(v3) 网站上看过,但找不到。
try {
// Call the search.list method to retrieve results matching the specified
// query term.
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_GET['q'],
'maxResults' => $_GET['maxResults'],
'type' => 'video',
**'videoCategoryId' => 'Music',**
));
music
的 videoCategoryID
是 10
。你可以在这里看到:
https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&id=10&key={YOUR_API_KEY}
所以你的代码最终看起来像这样:
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_GET['q'],
'maxResults' => $_GET['maxResults'],
'type' => 'video',
'videoCategoryId' => '10'
));
这是获取完整类别列表的快速而粗略的方法:
<?php
$ids = implode(",", range(1,50));
$JSON = file_get_contents("https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&id=" . $ids . "&key={YOUR-API-KEY}");
$json_data = json_decode($JSON, true);
foreach ($json_data['items'] as $category) {
echo $category['id'] . ' = ' . $category['snippet']['title'] . '<br/>';
}
?>