我正在尝试编写一个JavaScript代码,该代码可以通过将ID输入到var中来检测视频的许可证。因此,我查看了YouTube API的正式页面,然后想到了这个网址
https://www.googleapis.com/youtube/v3/videos?id=gwLej8heN5c&part=status&key= {我的API密钥}
这将返回此结果
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "creativeCommon",
"embeddable": true,
"publicStatsViewable": true
这对我来说很好,因为我得到了“ license:creativeCommon”,但是我无法将其引入JavaScript函数中。注意:我尝试对其进行iframe设置,但是即使在代码中添加&output = embed后,iframe也不显示任何内容。
为了清楚起见,这是我打算使用的方法:
var result = // somehow to get the result from the API
function licensetype() {
var cheack = result.search("creativeCommon");
if ( cheack = -1 ) {
document.write("This video is not a creative Common");
} else {
document.write (" This video is a creativeCommon" );
那么有没有办法我可以在javascript变量中获得上面显示的结果?
根据我对您问题的理解,您可能需要尝试:
var check = result.license;
switch (check) {
case undefined:
// Property 'license' not in result
break;
case "creativeCommon":
// Found
break;
default:
// 'license' property exists but is not 'creativeCommon'
break;
}
我对YouTube的API并不十分熟悉,但是我假设可以将查询返回的结果解析为JSON对象。
希望这可以帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句