我正在做一个Youtube API教程,即使我在课堂上使用不同的IDE和服务器(老师在我使用Atom和XWAMP时使用XAMPP和Brackets),一切都很顺利但是有点奇怪对我来说。该课程刚开始时,老师使用此代码来调用Youtube的回复:
var nomeCanal = 'achannelname'; (will not reveal)
$(document).ready(function() {
$.get("https://www.googleapis.com/youtube/v3/channels", {
part: 'contentDetails',
forUsername: nomeCanal,
key: 'thatlongkeythatwetakeonyoutubeapidevsite'}, (will note reveal either)
function(data) {
console.log(data);
}
)
});
ps:“(不会透露)”不是代码的一部分。
好的,简单的东西,制作代码然后,当我打开我的“localhost / youtube”...事情看起来一切都好我的意思是,标题是自动“YouTube API v3”,这意味着它被识别除了当我打开控制台以获得Youtube响应时,它显示:
"Falha no carregamento do <script> com a fonte “http://localhost/youtube/js/jquery.js”. youtube:25
Falha no carregamento do <script> com a fonte “http://localhost/youtube/js/meuscript.js”."
基本上意味着:
"Fail to load <script> with "http://localhost...".youtube:25".
现在我感觉很迷茫。然后我想:“我在哪里宣布脚本?实际上,我在本地文件上得到了jquery.js和meuscript.js(myscript.js),浏览器也可以找到它......但是这一切?
我直接从教程类下载的所有基础文件......可能是某些版本问题?我不确定。事实上,老师完全按照我的方式做了,而且他的确与我不同。
我徘徊在互联网上试图找到我应该做什么,认为这是一个Mozilla问题,但事实是我在这里丢失了。
这是我的工作树(我想这就是你们怎么称呼它):
这看起来像一个愚蠢的问题,答案可能就在我的鼻子前面,但请对我好,我发誓我尽力追求这个答案,这看起来很奇怪......讨厌做个新手我在哭。
@ user3210641问我的.html文件,我说它没有下载基本文件,实际上老师在当地没有html文件的情况下得到了他的回复......而且我是某人谁追求的东西我从Youtube API文档中复制了一个html开始样本,但它对我的本地主机没有任何影响。当我单独打开“quickstart.html”时,它只显示
"<p>YouTube Data API Quickstart</p>".
就是这样:
<!DOCTYPE html>
<html>
<head>
<title>YouTube Data API Quickstart</title>
<meta charset='utf-8' />
</head>
<body>
<p>YouTube Data API Quickstart</p>
<!--Add buttons to initiate auth sequence and sign out-->
<button id="authorize-button" style="display: none;">Authorize</button>
<button id="signout-button" style="display: none;">Sign Out</button>
<pre id="content"></pre>
<script type="text/javascript">
// Client ID and API key from the Developer Console
var CLIENT_ID = '135774447822-lb0tapejunq50ohi8t1gkc9n8eq9m3nt.apps.googleusercontent.com';
// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest"];
// Authorization scopes required by the API. If using multiple scopes,
// separated them with spaces.
var SCOPES = 'https://www.googleapis.com/auth/youtube.readonly';
var authorizeButton = document.getElementById('authorize-button');
var signoutButton = document.getElementById('signout-button');
/**
* On load, called to load the auth2 library and API client library.
*/
function handleClientLoad() {
gapi.load('client:auth2', initClient);
}
/**
* Initializes the API client library and sets up sign-in state
* listeners.
*/
function initClient() {
gapi.client.init({
discoveryDocs: DISCOVERY_DOCS,
clientId: CLIENT_ID,
scope: SCOPES
}).then(function () {
// Listen for sign-in state changes.
gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
// Handle the initial sign-in state.
updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
authorizeButton.onclick = handleAuthClick;
signoutButton.onclick = handleSignoutClick;
});
}
/**
* Called when the signed in status changes, to update the UI
* appropriately. After a sign-in, the API is called.
*/
function updateSigninStatus(isSignedIn) {
if (isSignedIn) {
authorizeButton.style.display = 'none';
signoutButton.style.display = 'block';
getChannel();
} else {
authorizeButton.style.display = 'block';
signoutButton.style.display = 'none';
}
}
/**
* Sign in the user upon button click.
*/
function handleAuthClick(event) {
gapi.auth2.getAuthInstance().signIn();
}
/**
* Sign out the user upon button click.
*/
function handleSignoutClick(event) {
gapi.auth2.getAuthInstance().signOut();
}
/**
* Append text to a pre element in the body, adding the given message
* to a text node in that element. Used to display info from API response.
*
* @param {string} message Text to be placed in pre element.
*/
function appendPre(message) {
var pre = document.getElementById('content');
var textContent = document.createTextNode(message + '\n');
pre.appendChild(textContent);
}
/**
* Print files.
*/
function getChannel() {
gapi.client.youtube.channels.list({
'part': 'snippet,contentDetails,statistics',
'forUsername': 'LucasCyrneFerreira'
}).then(function(response) {
var channel = response.result.items[0];
appendPre('This channel\'s ID is ' + channel.id + '. ' +
'Its title is \'' + channel.snippet.title + ', ' +
'and it has ' + channel.statistics.viewCount + ' views.');
});
}
</script>
<script async defer src="https://apis.google.com/js/api.js"
onload="this.onload=function(){};handleClientLoad()"
onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>
</body>
</html>
它在开始和结束时都有一些识别问题,但是代码是正确的,只是我在这里弄乱了将其改为代码的想法。