如何使用 php youtube data api php 回显所有视频 ID


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

你好朋友们,我想回显(打印)屏幕上的YouTube视频ID使用php

这是我到目前为止的代码。 任何人都可以告诉我如何只显示视频ID没有别的谢谢。

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

我已经为您调整了脚本,以便它将检索视频ID。

经过测试和工作片段

 <?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']); 
}