Youtube Data API - 未捕获的类型错误:无法读取未定义的属性“搜索" [英] Youtube Data API - Uncaught TypeError: Cannot read property 'search' of undefined
问题描述
我正在尝试让 Youtube Data API 的搜索部分工作,但运气不佳.
Hi I'm trying to get the Search part of the Youtube Data API to work but not having much luck.
我在遵循他们的教程的同时从 Youtube 的 GitHub 页面完全复制了代码
I completely copied the code from Youtube's GitHub page whilst following their tutorial
问题似乎出在这个函数上;
The problem seems to be with this function;
function search() {
var q = $('#query').val();
var request = gapi.client.youtube.search.list({
q: q,
part: 'snippet'
});
request.execute(function(response) {
var str = JSON.stringify(response.result);
$('#search-container').html('<pre>' + str + '</pre>');
});
}
任何帮助将不胜感激
谢谢;)
推荐答案
您的搜索功能中有一个错误,它最初没有让 JS 加载,后来又给了您未定义的错误.以下是正确的源代码:https://jsfiddle.net/aqwpg8ef/
There is a error in your search function, which does not let the JS load initially and which later gives you the undefined error. Following is the correct source code: https://jsfiddle.net/aqwpg8ef/
request = gapi.client.youtube.search.list({
q: 'q', //old one was without quotes
part: 'id, snippet', //the parts should be in quotes as well
type: 'video',
order: 'date'
});
主要是在 ajax 调用上进行搜索.20-22行附近
Mostly, on ajax call for search. near lines 20-22
希望有帮助!
干杯..
这篇关于Youtube Data API - 未捕获的类型错误:无法读取未定义的属性“搜索"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!