<?php
/*
* example_get_video.php
*
* @(#) $Id: example_get_video.php,v 1.3 2023/07/17 11:02:36 mlemos Exp $
*
*/
require('youtube_client.php');
$youtube = new youtube_client_class;
$youtube->key = ''; $application_line = __LINE__;
$youtube->key = '';
if(strlen($youtube->key) === 0)
{
die('Please go to Google Developer Console, '.
'https://console.cloud.google.com/apis/credentials'.
' and get a key for the YouTube API'.
'and set it in the line '.$application_line);
}
$parameters = array(
'id'=>'keMhManle0E'
);
$success = $youtube->ListVideos($parameters, $details);
?>
<!DOCTYPE html>
<html>
<head>
<title>Example of getting a video from YouTube</title>
</head>
<body>
<h1>Example of getting a video from YouTube</h1>
<?php
if($success)
{
$items = $details['items'];
if(count($items) === 0)
{
echo '<h2>No videos were returned.</h2>', "\n";
}
else
{
$item = $items[0];
$snippet = $item['snippet'];
$content = $item['contentDetails'];
echo '<h2>Returned videos: '. count($items), '</h2>', "\n";
echo '<h3>First video:</h3>', "\n";
echo '<p>Title: <a href="https://www.youtube.com/watch?v='.HtmlSpecialChars($parameters['id']).'">', HtmlSpecialChars($snippet['title']), '</a></p>', "\n";
echo '<p>Description: ', nl2br(HtmlSpecialChars($snippet['description'])), '</p>', "\n";
echo '<p>Duration: ', $youtube->ConvertDuration($content['duration']), ' seconds</p>', "\n";
echo '<p>Thumbnail: <img src="', HtmlSpecialChars($snippet['thumbnails']['standard']['url']), '"></p>', "\n";
}
echo '<pre>', HtmlSpecialChars(print_r($details, 1)), "\n", '</pre>';
}
else
echo 'Error: ', HtmlSpecialChars($youtube->error), "\n";
?>
</body>
</html>
|