Sai*_*man 3 php youtube parsing youtube-api youtube-data-api
以下是获取视频信息的网址,您必须在其中放置VIDEO-ID和API-KEY:
https://www.googleapis.com/youtube/v3/videos?part=snippet&id=VIDEO-ID-HERE&key=YOUR-API-KEY-HERE
Run Code Online (Sandbox Code Playgroud)
如何从中获取标题并将其保存为PHP中的变量?
沿着这些方向的某些内容将使用PHP客户端库为您提供与特定视频相关的信息:
<?php
require_once 'Google/autoload.php';
require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';
$client = new Google_Client();
$client->setDeveloperKey('{YOUR-API-KEY}');
$youtube = new Google_Service_YouTube($client);
$videoResponse = $youtube->videos->listVideos('snippet', array(
'id' => '{YOUR-VIDEO-ID}'
));
$title = $videoResponse['items'][0]['snippet']['title'];
?>
<!doctype html>
<html>
<head>
<title>Video information</title>
</head>
<body>
Title: <?= $title ?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
API请求的另一个解决方案
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function() {
$.get(
"https://www.googleapis.com/youtube/v3/videos",{
part : 'snippet',
id : 'VIODE_ID',
key: 'API_KEY'},
function(data) {
$.each( data.items, function( i, item ) {
alert(item.snippet.title);
});
}
);
});
</script>
Run Code Online (Sandbox Code Playgroud)