Get Youtube Video Details Using Json In PHP
1
Last update
There are two methodes to extract youtube video information.
Example:- 1
function yvJsonCurl($video_id)
{
$url = 'http://gdata.youtube.com/feeds/api/videos/'.$video_id.'?v=2&alt=json';
$ch = curl_init();
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
$result = json_decode($output,true);
return $result;
}
$video_id= 'Enter Video ID';
$result = yvJsonCurl($video_id);
$title = $result['entry']['media$group']['media$title']['$t'];//title
$description = $result['entry']['media$group']['media$description']['$t'];//description
$count = $result['entry']['yt$statistics']['viewCount']; //count
$dislikes = $result['entry']['yt$rating']['numDislikes']; //dislikes
$likes = $result['entry']['yt$rating']['numLikes']; //likes
$thumbnail = $result['entry']['media$group']['media$thumbnail'][0]['url'];//thumbnail
Example:- 2
function yv($video_id)
{
$url = 'http://gdata.youtube.com/feeds/api/videos/'.$video_id.'?v=2&alt=json';
$result = json_decode(file_get_contents($url), true);
return $result;
}
$video_id= 'Enter Video ID';
$result = yv($video_id);
$title = $result['entry']['media$group']['media$title']['$t'];//title
$description = $result['entry']['media$group']['media$description']['$t'];//description
$count = $result['entry']['yt$statistics']['viewCount']; //count
$dislikes = $result['entry']['yt$rating']['numDislikes']; //dislikes
$likes = $result['entry']['yt$rating']['numLikes']; //likes
$thumbnail = $result['entry']['media$group']['media$thumbnail'][0]['url'];//thumbnai