ted
ted

Reputation: 211

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 that i dont need.

Upvotes: 6

Views: 8252

Answers (5)

Oliver O'Neill
Oliver O'Neill

Reputation: 1254

<?
$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;

Upvotes: 4

nilskp
nilskp

Reputation: 3127

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

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

Upvotes: 0

ted
ted

Reputation: 211

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

experimental but working.

Upvotes: 2

Aaron W.
Aaron W.

Reputation: 9299

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

Upvotes: 6

Matt Asbury
Matt Asbury

Reputation: 5672

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

Upvotes: 1

Related Questions