Google API客户端ID不是't授权
Google API client ID isn't authorizing
我正在尝试制作一个应用程序来对youtube视频进行基本搜索。我正在使用Youtube Data API,我去了谷歌开发者的控制台,为我的域名创建了一个客户端ID。
我下载了谷歌示例代码部分的auth.js和search.js,并将我的客户端ID放在上面写着"我的客户端ID"的地方,但应用程序不起作用。我使用了console.log,似乎没有通过函数"checkAuth"。
我是不是错过了什么??以下是该页面的链接:http://www.vidme.cassandraburnscreative.com/#search
这是auth.js和search.js在一起的
var OAUTH2_CLIENT_ID = 'my client ID';
var OAUTH2_SCOPES = [
'https://www.googleapis.com/auth/youtube'
];
googleApiClientReady = function() {
console.log("googleApiClientReady");
gapi.auth.init(function() {
window.setTimeout(checkAuth, 1);
console.log("gapi.auth.init");
});
}
function checkAuth() {
gapi.auth.authorize({
client_id: OAUTH2_CLIENT_ID,
scope: OAUTH2_SCOPES,
immediate: true
}, handleAuthResult);
console.log("checkAuth");
}
function handleAuthResult(authResult) {
if (authResult && !authResult.error) {
// Authorization was successful. Hide authorization prompts and show
// content that should be visible after authorization succeeds.
$('.pre-auth').hide();
$('.post-auth').show();
loadAPIClientInterfaces();
console.log("Load Interfaces");
} else {
$('#login-link').click(function() {
console.log("nope");
gapi.auth.authorize({
client_id: OAUTH2_CLIENT_ID,
scope: OAUTH2_SCOPES,
immediate: false
}, handleAuthResult);
console.log("HandleAuthResult");
});
}
}
function loadAPIClientInterfaces() {
gapi.client.load('youtube', 'v3', function() {
handleAPILoaded();
console.log("handleAPILoaded");
});
}
function handleAPILoaded() {
$('#search-button').attr('disabled', false);
}
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>');
});
}
和html
<div class="wrapper">
<div id="buttons">
<p>Search For an Artist:</p>
<label> <input id="query" placeholder='+ Add Artist' type="text"/>
<button id="search-button" disabled onclick="search()">Search</button>
</label>
</div>
<div id="search-container">
</div>
</div>
您不需要连接或使用Oauth2使用YouTube API搜索内容。您只需要一个api密钥。
示例:
function googleApiClientReady() {
var apiKey = 'YOUR_API_KEY';
gapi.client.setApiKey(apiKey);
gapi.client.load('youtube', 'v3', function() {
isLoad = true;
});
request = gapi.client.youtube.search.list({
q: q,
part: 'snippet'
});
request.execute(function(response) {
//your code to here
});
}
不要忘记将此文件添加到您的index.html中,并在之后添加以下行:
<script src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script>
从文档YouTube API
相关文章:
- JavaScript数组排序(函数)用于对表行进行排序,而不是排序
- Node.js v6.2.0类扩展不是函数错误
- 直接下载文件,而不是从window.open(url)
- 使用压缩的JavaScript文件(不是运行时压缩)
- 控制台返回var不是't定义,但它是
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- 为什么会出现错误;未捕获的类型错误:undefined不是函数;
- 为什么不是't窗口.恢复正常工作吗?(javascript/jquery)
- 后焦点更改为IE 11中的地址栏,而不是转移到表单中的下一个控件
- 文本框不是从Javascript/Asp.net中的对话框中打印出来的
- 为什么不是't运行此Javascript的Chrome
- MongoDB (php) - 以数组而不是多个属性的形式返回文档属性
- 禁用(而不是隐藏)浏览器滚动条
- 为什么会出现错误,“UncaughtTypeError:undefined不是函数”
- TypeError:_this.store.getState在使用来自Redux的连接时不是函数
- 将谷歌自动完成地址信息放在页面上,而不是表格中
- 推荐在JavaScript中执行存储为字符串的函数,而不是使用eval
- //而不是在src=“”上使用http://"属性
- servlet中的请求对象,而不是从jsp接收参数值
- Google API客户端ID不是't授权