Jim Jim - 1 year ago 60
PHP Question

How to echo all video ids using php youtube data api php

Hello friends I want to echo ( print ) only youtube video ids on screen using php

here it is my code so far. can any one please tell me how to just show videos id nothing else thanks.

$data = file_get_contents("https://www.googleapis.com/youtube/v3/search?maxResults=5&part=snippet&key=AIzaSyBqXp0Uo2ktJcMRpL_ZwF5inLTWZfsCYqY");
$array = json_decode ($data,true);
print_r ($array);

Answer Source

I've adjusted the script for you so that it will retrieve the video id.

Tested and working snippet

$apiKey = "enter-your-apikey-here";
$data = file_get_contents("https://www.googleapis.com/youtube/v3/search?maxResults=5&part=snippet&key=".$apiKey);
$array = json_decode ($data,true);
foreach($array['items'] as $data) {