Aar*_*ndt 31 javascript youtube api title
我现在正在玩Youtube API,我开始了一个小项目(为了好玩).
问题是我无法找到从Id获取视频标题的方法.(例如:ylLzyHk54Z0)
我查看了DATA和PLAYER api文档,但我找不到它.
如果有人知道如何做到这一点,或者有人可以帮助我找到这样做的方法,请帮助我.
注意:我正在使用javascript.它将是一个网络应用程序.
编辑:我有一个想法.也许使用Regular expresion来解析页面标题中的标题.我正在研究这个问题.
Sim*_*ver 35
因为你试图从不同的域获取文档,所以在javascript中完全不可能.如果你很乐意投入一些PHP试试这个.测试好了:
<?
$vidID = $_POST['vidID'];
$url = "http://gdata.youtube.com/feeds/api/videos/". $vidID;
$doc = new DOMDocument;
$doc->load($url);
$title = $doc->getElementsByTagName("title")->item(0)->nodeValue;
?>
<html>
<head>
<title>Get Video Name</title>
</head>
<body>
<form action="test.php" method="post">
<input type="text" value="ID Here" name="vidID" />
<input type="submit" value="Get Name" />
</form>
<div id="page">URL: [<?= $url ?>]</div>
<div id="title">Title: [<?= $title ?>]</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
cba*_*rri 25
这就是使用JavaScript和V3 YouTube Data API的方法.
var ytApiKey = "...";
var videoId = "ylLzyHk54Z0";
$.get("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=" + videoId + "&key=" + ytApiKey, function(data) {
alert(data.items[0].snippet.title);
});
Run Code Online (Sandbox Code Playgroud)
pow*_*tac 15
打电话http://gdata.youtube.com/feeds/api/videos/ylLzyHk54Z0.
在此XML文件中,读取<title>标记的值.
Cam*_*mel 14
您可以使用JSON请求: http://gdata.youtube.com/feeds/api/videos/ylLzyHk54Z0?v=2&alt=jsonc
截至 2015 年 12 月,此答案准确无误。
要从 YouTube 视频 ID 获取视频标题,您必须使用 YouTube 数据 API 构建以下 URL(您需要使用 API 密钥,否则请求将失败):
https://www.googleapis.com/youtube/v3/videos?part=snippet&id={YOUTUBE_VIDEO_ID}&fields=items(id%2Csnippet)&key={YOUR_API_KEY}
执行 GET 请求,您将获得类似于以下块的 JSON 响应。对于标题来说,它存在于snippet/title键中。
{
"items":[
{
"id":"Jglv0A0qLI8",
"snippet":{
"publishedAt":"2014-06-30T03:42:20.000Z",
"channelId":"UCdTU5vd37FlTZ-xoB0xzRDA",
"title":"AIA Malaysia - A-Plus Venus Plan - Comprehensive Female Protection and Insurance Plan",
"description":"A comprehensive female protection plan for the modern women\n\nFor more information visit: http://www.aia.com.my/en/individuals/products-and-services/health/a-plus-venus-a-plus-venus-extra.html\n\nFor more products, visit AIA Malaysia's Products and Services playlist:\nhttps://www.youtube.com/playlist?list=PLSrgVT3aQ1fZ3SCe-dEVnFJDApBYkqolP\n\nFor more videos. subscribe to AIA Malaysia's YouTube channel:\nhttps://www.youtube.com/channel/UCdTU5vd37FlTZ-xoB0xzRDA",
"thumbnails":{
"default":{
"url":"https://i.ytimg.com/vi/Jglv0A0qLI8/default.jpg",
"width":120,
"height":90
},
"medium":{
"url":"https://i.ytimg.com/vi/Jglv0A0qLI8/mqdefault.jpg",
"width":320,
"height":180
},
"high":{
"url":"https://i.ytimg.com/vi/Jglv0A0qLI8/hqdefault.jpg",
"width":480,
"height":360
},
"standard":{
"url":"https://i.ytimg.com/vi/Jglv0A0qLI8/sddefault.jpg",
"width":640,
"height":480
},
"maxres":{
"url":"https://i.ytimg.com/vi/Jglv0A0qLI8/maxresdefault.jpg",
"width":1280,
"height":720
}
},
"channelTitle":"AIA Malaysia",
"tags":[
"aia",
"aia malaysia",
"a-plus venus",
"female health insurance",
"female life insurance",
"female insurance",
"female medical insurance"
],
"categoryId":"27",
"liveBroadcastContent":"none",
"localized":{
"title":"AIA Malaysia - A-Plus Venus Plan - Comprehensive Female Protection and Insurance Plan",
"description":"A comprehensive female protection plan for the modern women\n\nFor more information visit: http://www.aia.com.my/en/individuals/products-and-services/health/a-plus-venus-a-plus-venus-extra.html\n\nFor more products, visit AIA Malaysia's Products and Services playlist:\nhttps://www.youtube.com/playlist?list=PLSrgVT3aQ1fZ3SCe-dEVnFJDApBYkqolP\n\nFor more videos. subscribe to AIA Malaysia's YouTube channel:\nhttps://www.youtube.com/channel/UCdTU5vd37FlTZ-xoB0xzRDA"
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请访问API 文档页面。
| 归档时间: |
|
| 查看次数: |
53967 次 |
| 最近记录: |