gpt4 book ai didi

javascript - Youtube API 只搜索视频

转载 作者:行者123 更新时间:2023-11-30 05:41:15 24 4
gpt4 key购买 nike

我正在制作一个网站,允许用户输入两个关键字,它将在 YouTube API 中搜索这些关键字,但我的问题是。有时它会返回 channel 而不是视频。我怎样才能让它只返回视频?

这是我当前的代码;

// Your use of the YouTube API must comply with the Terms of Service:
// https://developers.google.com/youtube/terms
var YT = 'undefined';
// Helper function to display JavaScript value on HTML page.
function showResponse(response) {
YT = response;
}

// Called automatically when JavaScript client library is loaded.
function onClientLoad() {
gapi.client.load('youtube', 'v3', onYouTubeApiLoad);
}

// Called automatically when YouTube API interface is loaded (see line 9).
function onYouTubeApiLoad() {
// This API key is intended for use only in this lesson.
// See http://goo.gl/PdPA1 to get a key for your own applications.
gapi.client.setApiKey('AIzaSyD49-XZ2JV7Rws3KDM2T7nA56Jbi-O7djY');
}

function getRequest() {
var request = gapi.client.youtube.search.list({
part: 'snippet',
kind: 'youtube#video',
q: document.getElementById("artiest").value + " - " + document.getElementById("nummer").value,
});

// Send the request to the API server,
// and invoke onSearchRepsonse() with the response.
return request;

}

$(document).ready(function() {
$('#muziek').on('submit', function() {
var request = getRequest();
request.execute(function(response) {
$('#muziek').unbind('submit');
YT = response;
document.getElementById("VideoURL").value = YT.items[0].id.videoId;
$('#muziek').submit();
});
return false;
});
});

最佳答案

在函数 getRequest() 中,在您的搜索选项中,删除“kind”,您应该设置 type : 视频。

Here's the doc.

关于javascript - Youtube API 只搜索视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20702042/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com