Amber
Amber

Reputation: 73

How to get the entire YouTube Video description, php, gdata

I have php code that correctly retrieves, using the YouTube api, the title, video url, viewcount, video date, last comment date, and the first 160 characters of the description. I can't seem to figure out how to get the entire description. I know it is there in the xml retrieved, because I have dumped that. So how come I am only getting 160 chars?

The entire description is truncated at 157 chars, and "..." is added, so that by the time I echo it or var_dump it, it is 160 chars. Here is my complete test code (without title, video url, etc etc).

<?php 
    $feedURL = 'http://gdata.youtube.com/feeds/api/videos?q=phone&v=2&fields=entry[yt:statistics/@viewCount > 10000]&start-index=1&max-results=1';
    $sxml = simplexml_load_file($feedURL);
    foreach ($sxml->entry as $entry) {
        $media = $entry->children('http://search.yahoo.com/mrss/');
        echo $media->group->description;
    }
?>

This is what displays on the page:

FREE TuTiTu's Games: http://www.tutitu.tv/index.php/games FREE TuTiTu's Coloring pages at: http://www.tutitu.tv/index.php/coloring Join us on Facebook: https...

When I get the xml this way:

gdata.youtube.com/feeds/api/videos/JI-5kh_4gO0?v=2&alt=json-in-script&callback=youtubeFeedCallback&prettyprint=true

The entire description looks like this:

"media$description": {
"$t": "FREE TuTiTu's Games: http://www.tutitu.tv/index.php/games\nFREE TuTiTu's Coloring pages at: http://www.tutitu.tv/index.php/coloring\nJoin us on Facebook: https://www.facebook.com/TuTiTuTV\nTuTiTu's T-Shirts: http://www.zazzle.com/TuTiTu?rf=238778092083495163\n\nTuTiTu - The toys come to life\n\nTuTiTu - \"The toys come to life\" is a 3D animated television show targeting 2-3 year olds. Through colorful shapes TuTiTu will stimulate the children's imagination and creativity. On each episode TuTiTu's shapes will transform into a new and exciting toy.",
"type": "plain"
},

I'm sure I am missing something basic, but when I've looked for a solution, I have not found it.

Thanks for any help.

Upvotes: 3

Views: 3937

Answers (2)

Als
Als

Reputation: 1415

These 2 different types of API requests will return a different description size. I assume it's a way to limit the total response size.

1) doing a search as in: http://gdata.youtube.com/feeds/api/videos?q=phone&v=2&fields=entry&alt=json&prettyprint=true will return the short video description.
2) doing a video request as in: http://gdata.youtube.com/feeds/api/videos/JI-5kh_4gO0?v=2&alt=json&prettyprint=true will return the long video description.

BTW: api version 3 will allow you to request a list of video id's in 1 request (to get their long descriptions).

Upvotes: 3

Lylo
Lylo

Reputation: 1261

$media->group->{'media$description'} should do the trick

Upvotes: 1

Related Questions