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;

?>

,


STK433-090 Sanyo Original Pull Semiconductor picture

STK433-090 Sanyo Original Pull Semiconductor

$19.45



TA-200W Original New Kenwood Semiconductor picture

TA-200W Original New Kenwood Semiconductor

$250.00



200pcs NPN / PNP 10 Value Precision Transistor Assortment Kit picture

200pcs NPN / PNP 10 Value Precision Transistor Assortment Kit

$9.75



10PCS/ NEW Ramtron FM1608-120-P Semiconductor picture

10PCS/ NEW Ramtron FM1608-120-P Semiconductor

$45.66



B&K Precision Model 501A Semiconductor Curve Tracer picture

B&K Precision Model 501A Semiconductor Curve Tracer

$135.00



DCA55 Peak Atlas Semiconductor Tester Transistor MOSFET Diode Analyzer DCA 55 picture

DCA55 Peak Atlas Semiconductor Tester Transistor MOSFET Diode Analyzer DCA 55

$95.94



BRAND NEW 4 PCS HG (HuaGao) 2SC2879 HG semiconductor USA SELLER FREE FAST SHIP picture

BRAND NEW 4 PCS HG (HuaGao) 2SC2879 HG semiconductor USA SELLER FREE FAST SHIP

$154.95



Peak DCA75 Pro Latest Advanced Semiconductor Analyzer w Curve Tracing Atlas New picture

Peak DCA75 Pro Latest Advanced Semiconductor Analyzer w Curve Tracing Atlas New

$176.84



Allen Bradley 156-B20CB1 Semiconductor Contactor 4-32 VDC 20 Amp STOCK K-3387 picture

Allen Bradley 156-B20CB1 Semiconductor Contactor 4-32 VDC 20 Amp STOCK K-3387

$89.99



PNX1302EH picture

PNX1302EH

$95.00



Powered by WordPress. Designed by WooThemes