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;

?>

,


MSA altair 4X multi gas meter monitor detector(No Power Cord) Tested&Working picture

MSA altair 4X multi gas meter monitor detector(No Power Cord) Tested&Working

$249.99



Telonic Altair 8551 Neg Crystal Detector 100KHz-1.5GHz BNC(m-f) RF Microwave picture

Telonic Altair 8551 Neg Crystal Detector 100KHz-1.5GHz BNC(m-f) RF Microwave

$270.12



Altair 220 Ceiling Lift  picture

Altair 220 Ceiling Lift

$700.00



MSA Altair 5X / 5 Brass Push-On Fittings picture

MSA Altair 5X / 5 Brass Push-On Fittings

$25.00



Jim Pak Intel 8080A CPU processor New Old Stock from 1970's Imsai, Altair Stuff picture

Jim Pak Intel 8080A CPU processor New Old Stock from 1970's Imsai, Altair Stuff

$99.95



Jim Pak  NEC 8080A CPU processor New Old Stock from 1970's , Altair Stuff picture

Jim Pak NEC 8080A CPU processor New Old Stock from 1970's , Altair Stuff

$99.95



Jim Pak AMD  8080A CPU processor New Old Stock from 1970's Imsai, Altair Stuff picture

Jim Pak AMD 8080A CPU processor New Old Stock from 1970's Imsai, Altair Stuff

$99.95



MSA 5x altair gas detector Kit picture

MSA 5x altair gas detector Kit

$1349.99



Parker/MSA Pump Bracket Assembly, Altair 5 Gas Detector P/N 10088609  picture

Parker/MSA Pump Bracket Assembly, Altair 5 Gas Detector P/N 10088609

$80.00



MSA 10152605 XCELL ALTAIR 2X SINGLE GAS DETECTOR H2S-LC RPLCMNT SENSOR *OPENBOX* picture

MSA 10152605 XCELL ALTAIR 2X SINGLE GAS DETECTOR H2S-LC RPLCMNT SENSOR *OPENBOX*

$300.00



Powered by WordPress. Designed by WooThemes