How to get YouTube Keywords using PHP via URL? | YouTube API v3

  Do you want to create a PHP page that helps to extract the keywords using YouTube API v3? Create a PHP page to retrieve the keywords from YouTube Videos.

Required Knowledge

  1. PHP Programming Language
  2. CURL
  3. HTML & CSS

Let’s start if you have knowledge of PHP with the given requirements. As we know the youtube keywords create a big role in driving traffic to your youtube video. To get the Youtube Keywords or phrase through the youtube video URL, you need to access it via an API Key, you will get API Key from google credential as shown on this page get-API-google.

Table of Contents

Create Google API Key For YouTube API v3

In order to use YouTube API v3, the user needs to get the API key. You will get API Key credential from google credential as shown on this page get-API-google in steps.


Prepare URL

To get the data from YouTube API v3 here requires preparing a URL which helps in what types of data is needed and what types. Create a $var variable that contains the ID of Youtube Video e.g, mBJMkFNRVek . The following URL extracting title, description, and tags. It require the &fields and &part attribute to extract the snippet as &fields=items(snippet(title,description,tags)) and &part=snippet respectively.

Don’t forget to replace your Google API key in the following URL as shown &key=AIzaSyAIfYZNM5wRKRr3Z qyentZ_KFBDUapnl84


Create Form To Extract YouTube Keywords

Create a required Input Field in the form as shown below, the form contains URL input field and TextArea for input/output respectively.


<!DOCTYPE html>
<html lang='en'>

    <title>Youtube Keyword Extract Tool: Increase Views & Subscribers</title>
	<link rel="stylesheet" href="" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

		<h1 > DEMO of Youtube API v3 , reterive or extract keywords from Youtube Videos </h1>

		<div class=" w-100 d-flex align-items-center d-flex justify-content-center">
		<form action="" method="post" name="form">
			   <h5>Enter a Youtube Url to get Keyword or phrase :</h5>
					<div class="input-field" >
						<div class='inside-form'>
							<input type="text" class="form-control form-input"  name="youtubeData" id="youtubecaption" placeholder="Enter youtube url here" ></input>
						<div class='inside-form2'> 
							<input type="submit" href="#captionD" class="btn btn-primary codeNaiveBTN" name="getButton" id="test" value="Get !"> </input><br/>

					<div class="box-vertical">
								<label ><?php echo $word_count?> </label>

					<div class="box-vertical ">
						<textarea id="captionD" class="captionData w-100 " height="400px"><?php echo $extracted_data;?></textarea>


Create PHP Code To Perform The Back-End Operations

Create a PHP code that helps to extract the keywords, the following code has two variables $extracted_data and $word_count that store the information regarding keywords and word counts respectively. Create getKeywords() function which executes the prepared URL and returns the JSON file. After the successful execution of the CURL code, it decodes the JSON format file and extracts the required data e.g tags (youtube keywords) then saves it into the $extracted_data variable.


$extracted_data= '';
if (isset($_POST['getButton'])) {
	//echo $var1;
			$word_count='<h2 style="color:red;!important" >Total Keyword Found : '. str_word_count($extracted_data)."</h2>";
			$word_count='<h2 style="color:green;!important" >Total Keyword Found: '. str_word_count($extracted_data)."</h2>";

function getKeywords($var){
		$ch = curl_init();
		$extracted_data = '';
		curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, $site);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_VERBOSE, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $response = curl_exec($ch);
        $data = json_decode($response);
		$value = json_decode(json_encode($data), true);
			throw new Exception();
			$title = $value['items'][0]['snippet']['title'];
			$data= $value['items'][0]['snippet']['tags'];
			for($i=0; $i<count($data);$i++)
				$extracted_data =($extracted_data.$data[$i].', ');
		catch(Exception $e){
			echo '<script>alert("unable to get from this url")</script>'; 
	return $extracted_data;


Output Of YouTube API v3 Keyword Extract

The output of created form above which takes the YouTube Video URL as an input and show the output into the TextArea :

Example of YouTube API v3 – Input

The output of extracted youtube-keywords from the given YouTube Video URL and shows the output into the Textarea :

Example of YouTube API v3 – Output

Download Full YouTube API v3 Code From Here 

Leave a Reply

Your email address will not be published. Required fields are marked *