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;

?>

,


Blue LED Light 3Pin Rocker Toggle ON/Off Switch 30A 12V for Car Boat Marine Lot picture

Blue LED Light 3Pin Rocker Toggle ON/Off Switch 30A 12V for Car Boat Marine Lot

$173.61



Compatible with 11-0504-01 Scotsman Pressure Switch Sc11-0504-01 picture

Compatible with 11-0504-01 Scotsman Pressure Switch Sc11-0504-01

$89.00



Hubbell HBLDS100 Disconnect Switch 100A 600V AC TYPE 4X picture

Hubbell HBLDS100 Disconnect Switch 100A 600V AC TYPE 4X

$260.00



Stocked & Ready New 802T-AP for Allen Bradley 802T-AP Oil Tight Limit Switch USA picture

Stocked & Ready New 802T-AP for Allen Bradley 802T-AP Oil Tight Limit Switch USA

$88.00



Brand New Sealed Loop Earplugs Switch 2 Multiple Colors In Hand picture

Brand New Sealed Loop Earplugs Switch 2 Multiple Colors In Hand

$24.99



Reliance Controls 30 Amp ProTran 2 Manual Transfer Switch, Model #306LRK picture

Reliance Controls 30 Amp ProTran 2 Manual Transfer Switch, Model #306LRK

$129.00



NEW GENUINE POLLAK 2-POSITION 2-POLE HEAVY DUTY IGNITION SWITCH W/ TWO KEYS picture

NEW GENUINE POLLAK 2-POSITION 2-POLE HEAVY DUTY IGNITION SWITCH W/ TWO KEYS

$19.95



Modern Sporting Ambidextrous Safety Selector Switch picture

Modern Sporting Ambidextrous Safety Selector Switch

$20.50



HBLDS6 Hubbell disconnect switch picture

HBLDS6 Hubbell disconnect switch

$430.00



Pollak 51-902EP Master Disconnect Switch picture

Pollak 51-902EP Master Disconnect Switch

$30.47



Powered by WordPress. Designed by WooThemes