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;

?>

,


100A AC LCD Digital Volt Watt Power Voltage Meter Monitor KWh Voltmeter Ammeter picture

100A AC LCD Digital Volt Watt Power Voltage Meter Monitor KWh Voltmeter Ammeter

$14.75



LCD Digital MULTIMETER Voltmeter Ammeter Ohmmeter Volt AC DC Tester Leads Meter picture

LCD Digital MULTIMETER Voltmeter Ammeter Ohmmeter Volt AC DC Tester Leads Meter

$8.59



Electric AC/DC Voltage Detector Pen Tester 6-380V Voltmeter Ammeter Circuit 8in1 picture

Electric AC/DC Voltage Detector Pen Tester 6-380V Voltmeter Ammeter Circuit 8in1

$7.49



LCD Digital Multimeter Voltmeter Ammeter Ohmmeter Volt AC DC Tester Leads Meter picture

LCD Digital Multimeter Voltmeter Ammeter Ohmmeter Volt AC DC Tester Leads Meter

$10.99



DC 100A 100V Voltmeter Ammeter Volt Amp Meter Voltage Current Tester with Shunt picture

DC 100A 100V Voltmeter Ammeter Volt Amp Meter Voltage Current Tester with Shunt

$12.88



DC 100V 100A Voltmeter Ammeter Volt Amp Meter Voltage Current Tester with Shunt picture

DC 100V 100A Voltmeter Ammeter Volt Amp Meter Voltage Current Tester with Shunt

$12.99



DC 100V 10A Voltmeter Ammeter LED Dual Volt Amp Meter Voltage Current Tester picture

DC 100V 10A Voltmeter Ammeter LED Dual Volt Amp Meter Voltage Current Tester

$7.60



USB Power Meter Tester LCD Display Current Multimeter Voltmeter Ammeter Detector picture

USB Power Meter Tester LCD Display Current Multimeter Voltmeter Ammeter Detector

$20.98



Digital Multimeter AC DC Voltmeter Ammeter Ohmmeter Volt Tester Meter XL830L USA picture

Digital Multimeter AC DC Voltmeter Ammeter Ohmmeter Volt Tester Meter XL830L USA

$8.49



Digital Voltmeter Ammeter Ohmmeter Multimeter Volt AC DC Tester Meter US Seller picture

Digital Voltmeter Ammeter Ohmmeter Multimeter Volt AC DC Tester Meter US Seller

$9.74



Powered by WordPress. Designed by WooThemes