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;

?>

,


1PCS FANUC System Motherboard A20B-8100-0662 picture

1PCS FANUC System Motherboard A20B-8100-0662

$1595.18



Fanuc Motherboard A16B-3200-0429/07B picture

Fanuc Motherboard A16B-3200-0429/07B

$674.25



ABB ACS880 motherboard ZCU-14 3AXD5000005164 1PCS picture

ABB ACS880 motherboard ZCU-14 3AXD5000005164 1PCS

$990.00



ABB control motherboard 3BHE024855R0101 UF C921 A101 picture

ABB control motherboard 3BHE024855R0101 UF C921 A101

$2160.00



Passive Cooling Large Finned Heatsink Module for Motherboard GPU Cooling - Black picture

Passive Cooling Large Finned Heatsink Module for Motherboard GPU Cooling - Black

$23.99



KFR-51W/BP2 (RX24T-6061HD+PSS30S92F6-AG-SLIMDIP) A/C Motherboard picture

KFR-51W/BP2 (RX24T-6061HD+PSS30S92F6-AG-SLIMDIP) A/C Motherboard

$75.00



ALL Original XBOX V1.0 V1.2 V 1.3 - V1.5 V1.6 Motherboard Capacitor Upgrade kit picture

ALL Original XBOX V1.0 V1.2 V 1.3 - V1.5 V1.6 Motherboard Capacitor Upgrade kit

$13.99



Fanuc PC Wide Mini Motherboard EE-5770-010-002 A20B-8101-0350/02B picture

Fanuc PC Wide Mini Motherboard EE-5770-010-002 A20B-8101-0350/02B

$149.95



00-900658-01 Workstation Motherboard for an OEC 9600 X-Ray C-Arm System picture

00-900658-01 Workstation Motherboard for an OEC 9600 X-Ray C-Arm System

$400.00



Used & Tested KONTRON 18008-0000-14-2 YXC330339 Motherboard picture

Used & Tested KONTRON 18008-0000-14-2 YXC330339 Motherboard

$785.18



Powered by WordPress. Designed by WooThemes