Skip to main content

Fetch All Youtbe Video Titles Using Yoututbe API in PHP

 Its not a big deal to fetch all the YouTube titles using YouTube API

Step 1:

Make an Html form and save your file named as index.php. Just paste the below code in your index.php

"<html>
<head>
<title>Youtube</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"/>
</head>
<body>
<div class="container">
<br>
<br>
<h1>Youtube Video Search Title</h1>
<form method="post" action ="">  
<div class="form-group">
  Name: <input class="form-control" type="text" name="search" id="search" value="">
  </div>
  
  <div class="form-group">
 <input class="btn-danger" type="submit" name="submit" value="Search">
  </div>
  </form>
  </div>
  </body>
</html>

<?php
if (isset($_POST['submit'])) {
$key = "AIzaSyCPwOqun2AuaQq_bWDQb4X7hehSRJ6vu4I";
$base_url = "https://www.googleapis.com/youtube/v3/search";
$max_results = 15;
$q = $_POST['search'];
$API_URL = $base_url."?part=snippet&q=".$q."&maxResults=".$max_results."&key=".$key;
$videosTitle = json_decode(file_get_contents($API_URL));
echo "<pre>";
print_r($videosTitle);
}
?>

"

Step 2:

Now run your server wamp, xamp or lamp and enter the specific URL of your folder

You will see a form and you can write the title which you want to get from Yoututbe. It will show you  all the results

Note:

Please make sure that you are using your own key and base-URL correctly
In my case API key can URL is given below.
$key = "AIzaSyCPwOqun2AuaQq_bWDQb4X7hehSRJ6vu4I";
$base_url = "https://www.googleapis.com/youtube/v3/search";



Comments