I\'m playing now with the Youtube API and I began a small project (for fun).
The problem Is that I cant find the way to get Title of a video from the Id. (example: y
Instead of using http://gdata.youtube.com/feeds/api/videos/....
If you have the video loaded, you can use the player object's getVideoData() method to retrieve information on the video, including the title. It will return a object which contains: video_id, author, title.
The answers of Robert Sim and cbaigorri were the best, that's the correct way to do it at this time with JS, do GET request to:
https://www.googleapis.com/youtube/v3/videos?part=snippet&id={YOUTUBE_VIDEO_ID}&fields=items(id,snippet)&key={YOUR_API_KEY}
A little specification about this: You can use comma separated youtube video IDs to get multiple videos info in one request.
To get 1 video, replace {YOUTUBE_VIDEO_ID}
with video ID (ex: 123456
)
To get more videos in one request, replace {YOUTUBE_VIDEO_ID}
with comma separated IDs (ex: 123456,234567,345678,456789
)
This will count as a single request in the Quotas, this way you can get a lot of video details with only 1 quota/request cost.
Not entirely possible in javascript since you are trying to get a document from a different domain. If you are happy to throw in a bit of php try this. Tested ok:
<?
$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>
Call http://gdata.youtube.com/feeds/api/videos/ylLzyHk54Z0
.
In this XML file, read the value of the <title>
tag.
YouTube Api Documentation
You can use a JSON request to: http://gdata.youtube.com/feeds/api/videos/ylLzyHk54Z0?v=2&alt=jsonc
This is how you can do it with JavaScript and the 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);
});