Hello everyone, Can anyone help me with this question: I want to add Youtube videos related to certain keywords to my websites news section. I found that this link works very well as search query feed: http://gdata.youtube.com/feeds/api/videos?q=MY SEARCH KEYWORDS&orderby=relevance&max-results=3 The problem is, how to display given feed results on my website with php (would be the best for seo reasons) or JavaScript.. or any other way? Any help would be really appreciated
If anyone needs solution, here it is: $feedURL = "http://gdata.youtube.com/feeds/api/videos/?q={$q}&orderby=relevance&max-results=2"; // read feed into SimpleXML object $sxml = simplexml_load_file($feedURL); // get summary counts from opensearch: namespace $counts = $sxml->children('http://a9.com/-/spec/opensearchrss/1.0/'); $total = $counts->totalResults; Show results: foreach ($sxml->entry as $entry) { // get nodes in media: namespace for media information $media = $entry->children('http://search.yahoo.com/mrss/'); // get video player URL $attrs = $media->group->player->attributes(); $watch = $attrs['url']; // get video thumbnail $attrs = $media->group->thumbnail[1]->attributes(); $thumbnail = $attrs['url']; // get <yt:duration> node for video length $yt = $media->children('http://gdata.youtube.com/schemas/2007'); $attrs = $yt->duration->attributes(); $length = $attrs['seconds']; // get <gd:rating> node for video ratings $gd = $entry->children('http://schemas.google.com/g/2005'); if ($gd->rating) { $attrs = $gd->rating->attributes(); $rating = $attrs['average']; } else { $rating = 0; } // print record echo $watch; // This will output ONLY ID of video, but you get the idea. } } PHP: