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: ylLzyHk54Z0)
I have looked in the DATA and PLAYER api documentation and I cannot find it.
If someone knows how to do this or if someone could help me find the way to do this, please help me.
NOTE: I'm using javascript. It will be a web app.
EDIT: I have got an Idea. Maybe using a Regular expresion to parse out the title from the page title. I'm working on this.
As Scott explains, YouTube's video ID system, which can be seen in any URL that leads to one of the site's uploads, uses a 64-character language. That means, for each of the 11 spaces in one Video ID, there are 64 different characters that can be used.
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>
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); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With