我如何获得YouTube视频的标题,如果我有视频ID? [英] How do I get the title of a youtube video if I have the Video Id?

查看:556
本文介绍了我如何获得YouTube视频的标题,如果我有视频ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用YouTube API现在玩,我开始一个小项目(乐趣)。

I'm playing now with the Youtube API and I began a small project (for fun).

问题是,我无法找到摆脱的ID的视频标题的方式。 (例如:ylLzyHk54Z0)

The problem Is that I cant find the way to get Title of a video from the Id. (example: ylLzyHk54Z0)

我看过的资料和播放器API文档中,我无法找到它。

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.

请注意:我使用的JavaScript。这将是一个Web应用程序。

NOTE: I'm using javascript. It will be a web app.

编辑:我有一个想法。也许使用常规的前presion公司解析出从页面标题标题。我在做这个。

I have got an Idea. Maybe using a Regular expresion to parse out the title from the page title. I'm working on this.

推荐答案

未完全有可能在JavaScript,因为你正试图从一个不同的域的文档。如果你很高兴在一个位的PHP抛出试试这个。测试OK:

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>

这篇关于我如何获得YouTube视频的标题,如果我有视频ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆