Jim Jim - 7 months ago 25
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.

<?php
$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

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

Tested and working snippet

 <?php
$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) {
     var_dump($data['id']['videoId']); 
}