You are here:  » parsing youtube api output - always skips VIDEO_DETAILS


parsing youtube api output - always skips VIDEO_DETAILS

Submitted by vanarie on Sun, 2007-10-21 15:33 in

I'm trying to pull the video title and tags for this video, but magicparser always skips down to the comments section.

$url = "http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_id=*snip*&video_id=6kID5W9k-Zw";

MagicParser_parse($url,"myRecordHandler","xml|UT_RESPONSE/VIDEO_DETAILS");

Tried it on your demo page and it does the same thing. Is there a workaround for this?

The incoming data looks like this:

<ut_response status="ok">
<video_details>
<author>HappySlip</author>
<title>I dare you to! (Soap Opera #7)</title>
<rating_avg>4.65</rating_avg>
<rating_count>1923</rating_count>
<tags>happyslip soap opera #7 shadowtrader01</tags>
<description>
http://www.happyslip.com
Audrey & Claire. Do they dare...
http://www.youtube.com/shadowtrader01
</description>
<update_time>1192978755</update_time>
<view_count>112291</view_count>
<comment_count>1280</comment_count>
<upload_time>1192812866</upload_time>
<length_seconds>170</length_seconds>
<recording_date/>
<recording_location/>
<recording_country/>
<comment_list>
<comment>
<author>ezpar</author>
<text>
I thought she moved to LA?? The lanscape is not LA. Lookes like Seattle. LMAO
</text>
<time>1192979982</time>
</comment>
</comment_list>
<channel_list>
<channel>Comedy</channel>
</channel_list>
<thumbnail_url>http://img.youtube.com/vi/pEwp8HoNPEM/default.jpg</thumbnail_url>
<embed_status>ok</embed_status>
</video_details>
</ut_response>

Thanks.

Submitted by support on Mon, 2007-10-22 07:49

Hi,

I think the only problem with your example code is the format string, which should end in a trailing slash character, so instead of:

xml|UT_RESPONSE/VIDEO_DETAILS/

I've just tested this with the following code (view output):

<?php
  header
("Content-Type: text/plain");
  require(
"MagicParser.php");
  function 
myRecordHandler($record)
  {
    
print_r($record);
  }
  
MagicParser_parse("ut.xml","myRecordHandler","xml|UT_RESPONSE/VIDEO_DETAILS/");
?>

Hope this helps,
Cheers,
David.

Submitted by vanarie on Mon, 2007-10-22 15:13

I basically got it to work, but I don't understand something. I can print the returned values out inside the function, but when I try to pass them to variables to be used outside of it, the values are blank. What am I don't wrong here?

MagicParser_parse($url,"myRecordHandler","xml|UT_RESPONSE/VIDEO_DETAILS/");
// DOESN'T WORK
echo $author.$title.$tags.$desc.$length.$channel;
function myRecordHandler($record){
    // This is where you write your code to process each record, such as loading a database
    // You can display the record contents using PHP's internal print_r() function:
    // print_r($record);
    // The following code will print out each field in your sample data:
    $author = $record["AUTHOR"];
    $title = $record["TITLE"];
    $tags = $record["TAGS"];
    $desc = $record["DESCRIPTION"];
    $length = $record["LENGTH_SECONDS"];
    $channel = $record["CHANNEL"];
// DOES WORK
    echo $record["AUTHOR"];
    echo $record["TITLE"];
    echo $record["TAGS"];
    echo $record["DESCRIPTION"];
    echo $record["LENGTH_SECONDS"];
    echo $record["CHANNEL"];
  }

Submitted by support on Mon, 2007-10-22 15:23

Hi,

You need to declare your variables as global inside myRecordHandler. Try this:

MagicParser_parse($url,"myRecordHandler","xml|UT_RESPONSE/VIDEO_DETAILS/");
echo $author.$title.$tags.$desc.$length.$channel;
function myRecordHandler($record){
    global $author,$title,$tags,$desc,$length,$channel;
    // This is where you write your code to process each record, such as loading a database
    // You can display the record contents using PHP's internal print_r() function:
    // print_r($record);
    // The following code will print out each field in your sample data:
    $author = $record["AUTHOR"];
    $title = $record["TITLE"];
    $tags = $record["TAGS"];
    $desc = $record["DESCRIPTION"];
    $length = $record["LENGTH_SECONDS"];
    $channel = $record["CHANNEL"];
  }

Cheers,
David.