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;

?>

,


Orange Pi Zero 2 Board 1GB RAM Dual-band WIFI Open Source Board for Android 10 picture

Orange Pi Zero 2 Board 1GB RAM Dual-band WIFI Open Source Board for Android 10

$38.89



1/2Ton Spreader Hydraulic Jaw Ram Half Coupler 1/4

1/2Ton Spreader Hydraulic Jaw Ram Half Coupler 1/4" NPT PORTA POWER KIT TOOLS

$35.00



Raspberry Pi Compute Module 4 CM4 8GB RAM 32GB eMMC Wireless CM4108032 picture

Raspberry Pi Compute Module 4 CM4 8GB RAM 32GB eMMC Wireless CM4108032

$178.00



10 pcs TI TMS 4116-15NL TMS4116 16 Pin, DIP 16, IC Chips Texas Instruments RAM picture

10 pcs TI TMS 4116-15NL TMS4116 16 Pin, DIP 16, IC Chips Texas Instruments RAM

$9.50



Raspberry Pi Compute Module 4 WiFi 8GB RAM 32GB eMMC - CM4108032 - USA Shipping picture

Raspberry Pi Compute Module 4 WiFi 8GB RAM 32GB eMMC - CM4108032 - USA Shipping

$175.00



Raspberry Pi Compute Module 4, Wifi, 8GB ram, 32GB eMMC - CM4108032 -  picture

Raspberry Pi Compute Module 4, Wifi, 8GB ram, 32GB eMMC - CM4108032 -

$197.98



Texas Instruments TI-84 Plus Silver Edition Graphing Calculator Pink RAM Clear picture

Texas Instruments TI-84 Plus Silver Edition Graphing Calculator Pink RAM Clear

$32.50



1MB BLANK RAM Card for HP 48GX Graphic Calculator FRESH BATTERY FREESHIP picture

1MB BLANK RAM Card for HP 48GX Graphic Calculator FRESH BATTERY FREESHIP

$79.99



Hewlett Packard HP 48G Graphing Calculator with Original Case 32k Ram picture

Hewlett Packard HP 48G Graphing Calculator with Original Case 32k Ram

$97.00



Eastwood Pro Former 90 Degree Hydraulic RAM Stainless Steel Tubing Bender picture

Eastwood Pro Former 90 Degree Hydraulic RAM Stainless Steel Tubing Bender

$619.99



Powered by WordPress. Designed by WooThemes