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

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

问题描述

我现在正在使用 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)

我查看了 DATA 和 PLAYER 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.它将是一个网络应用.

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

我有一个想法.也许使用正则表达式从页面标题中解析出标题.我正在研究这个.

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 试试这个.测试正常:

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>

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

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