搜索stackoverflow后,我发现:How can I retrieve YouTube video details from video URL using PHP?
使用以下代码(我已更改为https而不是http,并且还添加了$ _GET ['v']以从浏览器网址获取视频代码):
function get_youtube($url) {
$youtube = "https://www.youtube.com/oembed?url=". $url ."&format=json";
$curl = curl_init($youtube);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($curl);
curl_close($curl);
return json_decode($return, true);
}
$url = 'https://www.youtube.com/watch?v=' . $_GET['v'];
// Display Data
echo '<pre>';
print_r(get_youtube($url));
echo '</pre>';
我能够得到以下结果:
Array
(
[thumbnail_url] => https://i.ytimg.com/vi/AhN5MbTJ0pk/hqdefault.jpg
[version] => 1.0
[type] => video
[html] => <iframe width="480" height="270" src="https://www.youtube.com/embed/AhN5MbTJ0pk?feature=oembed" frameborder="0" allowfullscreen></iframe>
[provider_url] => https://www.youtube.com/
[thumbnail_width] => 480
[width] => 480
[thumbnail_height] => 360
[author_url] => https://www.youtube.com/user/AndreasChoice
[author_name] => AndreasChoice
[title] => GROSS SMOOTHIE CHALLENGE! ft. Tealaxx2
[height] => 270
[provider_name] => YouTube
)
哪个好,但我还需要检索缺少的视频的完整“描述”。我怎样才能做到这一点?谢谢。
答案 0 :(得分:5)