YouTube Data API V3 Using PHP

With the YouTube Data API, you can add a variety of YouTube features to your application. Use the API to upload videos, manage playlists and subscriptions, update channel settings, and more.
You need a Google Account to access the Google Developers Console, request an API key, and register your application.

For Search a querry:

<?php
$api_key = '###############################';
$search_api_url = 'https://www.googleapis.com/youtube/v3/search?part=snippet&q='.$search.'&maxResults='.$maxRecords.'&type=video&key=' . $api_key;
$search_data = json_decode(file_get_contents($search_api_url));
foreach($search_data->items as $mydata){
 $vid = $mydata->id->videoId;
 $vidThumburl= $mydata->snippet->thumbnails->high->url;
 $channel = $mydata->snippet->channelTitle;
 $vidTitle = $mydata->snippet->title;
 $playtime = $data->items[0]->contentDetails->duration;
 }
 ?>

For Getting Video Info By VideoID:

<?php
$api_key = '###########################';
 $api_url = 'https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails%2Cstatistics&id=' . $vid . '&key=' . $api_key;
 $data = json_decode(file_get_contents($api_url));
 echo '<script>document.title = "'.$data->items[0]->snippet->title.'";</script>';
 // Accessing Video Info
echo '<strong>Title: </strong>' . $data->items[0]->snippet->title . '<br>';
 echo '<strong>publishedAt: </strong>' . $data->items[0]->snippet->publishedAt . '<br>';
echo '<strong>Duration: </strong>' . $data->items[0]->contentDetails->duration . '<br>';
echo '<strong>Duration: </strong>' . $data->items[0]->statistics->viewCount . '<br>';
?>

Display a channel Videos By Channel ID:

<?php
$channelId = "UCxlQ4qrAWVHF-4OvD5CnSqg";
$channel_api_url = 'https://www.googleapis.com/youtube/v3/activities?part=snippet%2CcontentDetails&channelId=' . $channelId . '&maxResults=12&key=' . $api_key;
$channel_data = json_decode(file_get_contents($channel_api_url));
foreach($channel_data->items as $mydata){
 $vid = $mydata->contentDetails->upload->videoId;
 $vidThumburl= $mydata->snippet->thumbnails->high->url;
 $channel = $mydata->snippet->channelTitle;
 $vidTitle = $mydata->snippet->title;
 $publishedAt= $mydata->snippet->publishedAt;
 }
?>