Introduction
Youtube API for PHP to feed a video list from a particular channel without Oauth, this API only needs a Channel ID and Channel name. Youtube API is to demonstrate how to show video in our website without 0auth and API Key.
Background
This API is created for only a website to display a video list from their channel without 0auth & API key!
Using the Code
Basic PHP codes are used to feed a video list.
$channel_name="xyz123";
$channel="Uhjfhdkjhfdf454dfde";
$feedURL=urlencode('https://gdata.youtube.com/feeds/api/videos?author=
'.$channel.'&start-index=1&max-results=2&orderby=published');
if (@simplexml_load_file($feedURL))
{
$sxml = simplexml_load_file($feedURL);
$counts = $sxml->children('http://a9.com/-/spec/opensearchrss/1.0/');
$total = $counts->totalResults;
foreach ($sxml->entry as $entry) {
$media = $entry->children('http://search.yahoo.com/mrss/');
$attrs = $media->group->player->attributes();
$watch = $attrs['url'];
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];
$minute=floor($length/60);
$second=$length-$minute*60;
$gd = $entry->children('http://schemas.google.com/g/2005');
if ($gd->rating) {
$attrs = $gd->rating->attributes();
$rating = $attrs['average'];
} else {
$rating = 0;
}
$attrs = $media->group->thumbnail[1]
->attributes();
...
Points of Interest
Actually, it loads the video feed list from Google gdata URL. This simple API is to demonstrate how to show video in our website without 0auth.
History
- Version 1.0 - It just shows the feed list only, no link to the original video (Youtube URL) on each video in feed
- Version 1.0.1 - Link to the individual video is updated in a feed list