开发者

Youtube API - Title only

I know that i can get the whole info about a video by using:

http://gdata.youtube.com/feeds/api/videos/ID

but that outputs a lot of information and im using a regular expression to get the title out of it. I was wondering if there was a way to let that page only output the title and not all the other stuff t开发者_JAVA百科hat i dont need.


Not sure if this will help since I've never worked with youtube api before. I just ran across this info yesterday. According to http://dl.google.com/googleio/2010/googleapis-how-google-builds-apis.pdf you can do a Partial Get (just search that pdf for "Partial Response") by using fields=entry(title) (though I think it's for searching for videos). By querying for the actual video id instead of a string it will return just that one video.

Example:

http://gdata.youtube.com/feeds/api/videos?v=2&q=[video_id]&max-results=1&fields=entry(title)&prettyprint=true


<?
$id = 'VIDEOID';
$xmlData = simplexml_load_string(file_get_contents("http://gdata.youtube.com/feeds/api/videos/{$id}?fields=title"));

$title = (string)$xmlData->title;

echo $title;


http://gdata.youtube.com/feeds/api/videos/[id]?fields=title

experimental but working.


It returns an XML file so use simpleXML to parse it.


Prefix search term with "title:", like this:

http://gdata.youtube.com/feeds/base/videos?q=title:<search term>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜