Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the title of a youtube video if I have the Video Id?

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.

like image 834
Aaron de Windt Avatar asked Nov 19 '09 00:11

Aaron de Windt


People also ask

How does YouTube video ID work?

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.


2 Answers

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> 
like image 113
SimonDever Avatar answered Sep 21 '22 11:09

SimonDever


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); }); 
like image 41
cbaigorri Avatar answered Sep 17 '22 11:09

cbaigorri