Parsing YouTube V3 JSON with PHP Example

In this article we’re going over an example of how to parse the JSON output from the YouTube V3 API using PHP.

First you’ll need to login to the Google Developers Console and obtain your API key to use when making queries to the YouTube API.

The following code will execute your query to YouTube and display the title of the video along with a thumbnail and description.

<?

$apikey = “YOURKEY”;
$per_page = 6;
$search = “your search term”;
$category = “2”; //autos

$query = “https://www.googleapis.com/youtube/v3/search?part=snippet&q=$search&maxResults=$per_page&videoCategoryId=$category&safesearch=strict&key=$apikey”;

$json_file3 = file_get_contents(“$query”);

$jfo3 = json_decode($json_file3,true);

foreach($jfo3[‘items’] as $val) {

$title = $val[‘snippet’][‘title’];
$description = $val[‘snippet’][‘description’];
$id = $val[‘id’][‘videoId’];
$thumbnail_url = $val[‘snippet’][‘thumbnails’][‘default’][‘url’];

echo <<<EOF

<p><img width = “250” src = “$thumbnail_url” align = “right”></a>
<a href =”video-viewer.php?v=$id”>$title<BR>
$description</p><br clear=”all”><HR>

EOF;

?>

,


Server Book with 2 Zipper Pockets Leather Server Books for Waitress picture

Server Book with 2 Zipper Pockets Leather Server Books for Waitress

$8.46



Windows Server 2025 RDS CAL 50 User Key License | |Multilingual picture

Windows Server 2025 RDS CAL 50 User Key License | |Multilingual

$93.76



300 Million 2026 Consumer Database NEW Release - US OPT-IN  70+ Feeds Verticals picture

300 Million 2026 Consumer Database NEW Release - US OPT-IN 70+ Feeds Verticals

$3500.00



Allworx Connect 536 VOIP Server picture

Allworx Connect 536 VOIP Server

$178.19



Moxa 5610-8-DT NPort Serial to Ethernet Device Server Module 8-Port 12-48VDC picture

Moxa 5610-8-DT NPort Serial to Ethernet Device Server Module 8-Port 12-48VDC

$139.00



Server Book with 2 Zipper Pockets Leather Server Books for Waitress picture

Server Book with 2 Zipper Pockets Leather Server Books for Waitress

$7.99



Server Book for Waitress Book with Zipper Pocket, 5X9 Leopard Magnetic Closure S picture

Server Book for Waitress Book with Zipper Pocket, 5X9 Leopard Magnetic Closure S

$21.02



Server Server Pump Sp 82000 - Geniune OEM W Bottom picture

Server Server Pump Sp 82000 - Geniune OEM W Bottom

$125.00



MOXA NPort 5230 2-Port Device Server, 10/100 Ethernet, RS-232 x 1, RS-422/485... picture

MOXA NPort 5230 2-Port Device Server, 10/100 Ethernet, RS-232 x 1, RS-422/485...

$60.00



Schneider Electric PowerLogic EGX300 Web-Enabled Integrated Gateway-Server picture

Schneider Electric PowerLogic EGX300 Web-Enabled Integrated Gateway-Server

$304.00



Powered by WordPress. Designed by WooThemes