-1

There is an example how to search videos by search term in the documentation, but how to extract information from single video when you have the videoID.

<?php

  // set feed URL
    $feedURL = 'http://gdata.youtube.com/feeds/api/videos/LjhCEhWiKXk?v=2';

    // read feed into SimpleXML object
    $sxml = simplexml_load_file($feedURL);


// this get the video title
$videoTitle = $sxml->title;


?>

I get only the video title ... also there is no views count,description and duration.

hakre
  • 193,403
  • 52
  • 435
  • 836
Marian Petrov
  • 625
  • 2
  • 9
  • 21
  • Please provide the XML you get from the API. As you can see in http://codepad.viper-7.com/MvmSNA there will be elements with duration and viewcount in the returned XML. Maybe you just have problems [accessing namespaced elements and attributes?](http://stackoverflow.com/questions/6027398/php-simplexml-namespace-problem/6027507#6027507) – Gordon Jun 23 '12 at 16:33
  • 1
    Note that the v2 API allows you to tailor retrieval of feeds to only contain particular elements, so to get the title, viewcount, duration and description, you can use http://codepad.viper-7.com/NLlack – Gordon Jun 23 '12 at 17:03
  • Yes it shows the data I need but how to get the values ? – Marian Petrov Jun 23 '12 at 17:14
  • see the answer about namespaces I have linked above please. – Gordon Jun 23 '12 at 17:22
  • Warning: main() [function.main]: Node no longer exists on this line $entry->children('yt', true)->statistics->children()->value ); – Marian Petrov Jun 23 '12 at 17:26
  • I'm sure you'll figure it out. You got all the info you need now. – Gordon Jun 23 '12 at 17:31

1 Answers1

0

This was useful for me: Visit Use the YouTube API with PHP

You have to completely parse video entry ($sxml) to get more information:

Children nodes of Entry $sxml:

// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');

Get duration: ($media->children ...)

** Element yt:duration under the media:group element stores the length of the video, in seconds**

// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$obj->length = $attrs['seconds'];
user1203334
  • 283
  • 1
  • 3
  • 5