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;

?>

,


GenRad 1658 Precision RLC Digibridge Impedance Meter 1658-9700 picture

GenRad 1658 Precision RLC Digibridge Impedance Meter 1658-9700

$275.00



Ultrasonic Hardness Testercan ltrasonic contact impedance method to measure vari picture

Ultrasonic Hardness Testercan ltrasonic contact impedance method to measure vari

$495.00



Solartron Schlumberger SI-1260 Impedance Gain/Phase Analyzer 1255B picture

Solartron Schlumberger SI-1260 Impedance Gain/Phase Analyzer 1255B

$850.00



TBOH01 5µH Line Impedance Stabilisation Network - CISPR 25 picture

TBOH01 5µH Line Impedance Stabilisation Network - CISPR 25

$279.00



PASTERNACK PE7007 IMPEDANCE MATCHING PAD, DC-2 GHZ, 5.7 db LOSS picture

PASTERNACK PE7007 IMPEDANCE MATCHING PAD, DC-2 GHZ, 5.7 db LOSS

$58.00



HP Agilent 4194A Impedance / Gain-Phase Analyzer picture

HP Agilent 4194A Impedance / Gain-Phase Analyzer

$699.99



Goldline ZM1P Impedance Meter with Overload Protection picture

Goldline ZM1P Impedance Meter with Overload Protection

$673.33



NTI  MR-PRO, Audio Signal Generator w/impedance Measurement picture

NTI MR-PRO, Audio Signal Generator w/impedance Measurement

$950.00



Hewlett Packard HP: 4191A RF Impedance Analyzer, 1 - 1000MHz picture

Hewlett Packard HP: 4191A RF Impedance Analyzer, 1 - 1000MHz

$429.99



TBOH01 5µH Line Impedance Stabilisation Network - CISPR 25 picture

TBOH01 5µH Line Impedance Stabilisation Network - CISPR 25

$279.00



Powered by WordPress. Designed by WooThemes