如何使用Javascript / HTML5检索Youtube视频元数据? 请分享一些链接
答案 0 :(得分:1)
var xhr = new XMLHttpRequest();
xhr.open('GET', "https://www.googleapis.com/youtube/v3/videos?part=snippet&id=<video ID>&fields=items/snippet/title,items/snippet/description&key=<API key>");
xhr.send();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var response = JSON.parse(xhr.responseText);
// console.log("Description:", response.items[0].snippet.description);
// var text = response.items[0].snippet.description;
var text = "Find me at sand also at fgdyh thrj hrtyrt fhrtgh";
var html = findUrls(text);
function findUrls(text) {
var source = (text || '').toString();
var urlArray = [];
var url;
var matchArray;
// Regular expression to find FTP, HTTP(S) and email URLs.
var regexToken = /(((ftp|https?):\/\/)[\-\w@:%_\+.~#?,&\/\/=]+)|((mailto:)?[_.\w-]+@([\w][\w\-]+\.)+[a-zA-Z]{2,3})/g;
// Iterate through any URLs in the text.
while ((matchArray = regexToken.exec(source)) !== null) {
var token = matchArray[0];
urlArray.push(token);
}
答案 1 :(得分:-1)