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;

?>

,


120W Cordless Handheld Vacuum Cleaner 12000PA Portable Car Auto Home Wireless picture

120W Cordless Handheld Vacuum Cleaner 12000PA Portable Car Auto Home Wireless

$49.90



ProTeam SQV-100 Super Quartervac Backpack Vacuum Tested picture

ProTeam SQV-100 Super Quartervac Backpack Vacuum Tested

$259.99



ROBINAIR VACUMASTER 15400 HIGH PERFORMANCE VACUUM PUMP picture

ROBINAIR VACUMASTER 15400 HIGH PERFORMANCE VACUUM PUMP

$60.00



VEVOR 9

VEVOR 9" Drywall Sander 850W Vacuum System Folding 6 Speed LED Strip Light

$97.87



Shark UZ155 Pet Cordless Stick Vacuum with PowerFins and Self-Cleaning Brush picture

Shark UZ155 Pet Cordless Stick Vacuum with PowerFins and Self-Cleaning Brush

$99.00



Air Vacuum Pump HVAC AC Air Tool 3,5CFM 1/4hp + Manifold Gauge Set R134a Kit picture

Air Vacuum Pump HVAC AC Air Tool 3,5CFM 1/4hp + Manifold Gauge Set R134a Kit

$94.58



Oil Changer Vacuum Fluid Extractor Pneumatic/Manual 6.5 Liter with Pump Tank Rem picture

Oil Changer Vacuum Fluid Extractor Pneumatic/Manual 6.5 Liter with Pump Tank Rem

$49.99



BLACK DECKER HLVB315JP07W Furbuster Cordless Pet Handheld Vacuum with Motorized picture

BLACK DECKER HLVB315JP07W Furbuster Cordless Pet Handheld Vacuum with Motorized

$27.00



XtremepowerUS 4CFM Vacuum Pump HVAC Refrigeration AC Manifold Gauge r134 Tap picture

XtremepowerUS 4CFM Vacuum Pump HVAC Refrigeration AC Manifold Gauge r134 Tap

$149.95



VacPouch - Chamber Vacuum Pouches, 3mil, 500 PACK picture

VacPouch - Chamber Vacuum Pouches, 3mil, 500 PACK

$68.95



Powered by WordPress. Designed by WooThemes