我試圖寫一個簡單的youtube請求來使用youtube javascript api v3搜索視頻。簡單的youtube javascript api 3請求不起作用
這是源代碼:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function showResponse(response) {
var responseString = JSON.stringify(response, '', 2);
document.getElementById('response').innerHTML += responseString;
}
// Called automatically when JavaScript client library is loaded.
function onClientLoad() {
gapi.client.load('youtube', 'v3', onYouTubeApiLoad);
}
// Called automatically when YouTube API interface is loaded
function onYouTubeApiLoad() {
// This API key is intended for use only in this lesson.
gapi.client.setApiKey('API_KEY');
search();
}
function search() {
var request = gapi.client.youtube.search.list({
part: 'snippet',
q:'U2'
});
// Send the request to the API server,
// and invoke onSearchRepsonse() with the response.
request.execute(onSearchResponse);
}
// Called automatically with the response of the YouTube API request.
function onSearchResponse(response) {
showResponse(response);
}
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="https://apis.google.com/js/client.js?onload=onClientLoad" type="text/javascript"></script>
</head>
<body>
<pre id="response"></pre>
</body>
</html>
當我加載谷歌瀏覽這個頁面(更新),什麼也不會發生,頁面保持空白。 我已經請求瀏覽器應用程序的API密鑰(使用引用程序)並在方法gapi.client.setApiKey中複製。
任何人都可以幫到我嗎?
感謝
並在控制檯顯示的任何錯誤? (ctrl + shift + j in chrome) – asifrc
另外,你在'request 'cute(onSearchResponse)後面有一個無與倫比的'}';' – asifrc
試試這個例子的答案 –