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;

?>

,


Used Philips GE Samsung Medison Sonoscape Aloka Ultrasouns picture

Used Philips GE Samsung Medison Sonoscape Aloka Ultrasouns

$10.00



Samsung Xpress C1860FW C1810W ProXpress C2670FW Transfer Belt Unit JC96-06514A picture

Samsung Xpress C1860FW C1810W ProXpress C2670FW Transfer Belt Unit JC96-06514A

$200.00



SAMSUNG OfficeServ 7100 System With LOT Of (10) SMT-i5220S Phones picture

SAMSUNG OfficeServ 7100 System With LOT Of (10) SMT-i5220S Phones

$199.00



Samsung AR24HSFSJWKN

Samsung AR24HSFSJWKN "Wi-Fi Whisper" Wall Mount 24000 BTU

$196.70



Samsung Philips Ultrasound Devices Single Use Service Password picture

Samsung Philips Ultrasound Devices Single Use Service Password

$75.00



Dual Lens Borescope Endoscope Inspection Camera for iPhone iPad Samsung Android picture

Dual Lens Borescope Endoscope Inspection Camera for iPhone iPad Samsung Android

$25.96



Choice Parts DG44-01008A for Samsung Range Burner Infinite Control Switch picture

Choice Parts DG44-01008A for Samsung Range Burner Infinite Control Switch

$33.11



79904 - Hydraulic Conversion Adapter, Volvo/Samsung TIFCO Style C Connector picture

79904 - Hydraulic Conversion Adapter, Volvo/Samsung TIFCO Style C Connector

$20.00



Samsung 12,000 BTU/Hr Outdoor Heat Pump Unit | 208-230/1   MOD #AR12BSFCMWKXCV picture

Samsung 12,000 BTU/Hr Outdoor Heat Pump Unit | 208-230/1 MOD #AR12BSFCMWKXCV

$269.98



Samsung JC96-06221A Cyan Developer Unit MultiXpress CLX-9301NA picture

Samsung JC96-06221A Cyan Developer Unit MultiXpress CLX-9301NA

$199.99



Powered by WordPress. Designed by WooThemes