views:

1668

answers:

2

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.

+4  A: 

Call http://gdata.youtube.com/feeds/api/videos/ylLzyHk54Z0.

In this XML file, read the value of the <title> tag.

YouTube Api Documentation

powtac
+1  A: 

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>
Ambrosia
Thanks for your answer.Yes, PHP is not a problem. I was prepared for an ajax solution.
Aaron de Windt
Yeah some of it could be done differently in javascript but you'd still have that cross domain problem and no need to make it anymore complicated than it has to be. If you are happy I hope you will accept the answer :)
Ambrosia