Al right guys,这开车很疯狂 - 太疯狂了......尝试使用YOUTUBE DATA的好处构建一个互联网应用程序(它是一个学校项目),客户端会在输入搜索中键入一个查询字符串并显示结果 - json-我的代码将读取此响应并将其显示在DOM ELEMENT div和h1中。
Chrome向我显示错误
var request = gapi.client.youtube.***search.list***...
我试过:
<head>
<meta charset="utf-8" />
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="../static/content/ClientFinePage.css" />
<!--First Test -->
<script src="https://apis.google.com/js/platform.js?onload=onLoadCallback" async defer></script>
<!--Third Test With YouTube-->
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
<script src="../static/scripts/ClientFinePage.js"></script>
</head>
//this element dom for displaying results in results
<input class="search" name="searching" id="searchit" placeholder="Search..." />
<input type="button" id="search-button" onclick="SearchFromYouTube2()" class="search-button" value="" />
<div id="wrapper">
<iframe id="ytplayer" type="text/html" width="640" height="390"
src="http://www.youtube.com/embed/JeLPCETf0Ic"
frameborder="0" />
<div id="results">
</div>
</div>
//this script at the end of the file
<script type="text/javascript" src="https://apis.google.com/js/client.js?onload=init"></script>
和我的js文件ClientFinePage.js:
function SearchFromYouTube2() {
var q = $('#searchit').val();
gapi.client.setApiKey(apiKey_sucker);
gapi.client.load('youtube', 'v3', function () {
isLoad = true;
});
var request = gapi.client.youtube.***search.list***({ //<<< *error is here*
q: q,
part: 'snippet',
order: 'date'
});
request.execute(function (response) {
var str = JSON.stringify(response.result);
$('#results').html('<pre>' + str + '</pre>');
});
}
我已经按照有关使用youtube搜索功能的教程,但仍然收到此错误
注意:将脚本链接的位置更改为google api - 放在文件末尾会导致
未捕获的TypeError:无法读取属性&#39; gapi&#39;未定义的