I want to display the latest 5 videos of a youtube channel including title, views, thumbnail, etc. for a analysis.
But how can i display the next video after i displayed the first. because there is no id=1 for latest e.g.
So i want to dipslay the first video with details and then the secound one,etc.
I use PHP and HTML
{
"kind": "youtube#searchListResponse",
"etag": "\"nlUZBA6NbTS7q9G8D1GljyfTIWI/sqVszgEMcgndBQQW-8aekztyFWo\"",
"nextPageToken": "CAUQAA",
"regionCode": "DE",
"pageInfo": {
"totalResults": 313,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"nlUZBA6NbTS7q9G8D1GljyfTIWI/C8zU9hXFXvoOaiyzihj3QdaM3nk\"",
"id": {
"kind": "youtube#video",
"videoId": "eWTpXZ-sspk"
},
"snippet": {
"publishedAt": "2018-08-28T16:30:11.000Z",
"channelId": "UCzfu8Y5CsN7OCLJhZy_fH6w",
"title": "RBX.Tools - Earn FREE Robux! (3,000 Giveaway)",
"description": "Want to earn free robux? Our website allows you to do that easily without any limits! Check it out: https://rbx.tools Robux giveaway: ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/eWTpXZ-sspk/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/eWTpXZ-sspk/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/eWTpXZ-sspk/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "MRMURK4G3",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"nlUZBA6NbTS7q9G8D1GljyfTIWI/f-4ch1LXyzfYIL4utWuPz6CRFck\"",
"id": {
"kind": "youtube#video",
"videoId": "IVby2exqn1w"
},
"snippet": {
"publishedAt": "2018-02-09T23:38:15.000Z",
"channelId": "UCzfu8Y5CsN7OCLJhZy_fH6w",
"title": "How To: Setup/Use Discord Webhooks! (PHP)",
"description": "In this video i show you how to use discord webhooks for any custom event you would like using a simple cURL request in PHP. Find this video helpful in any ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/IVby2exqn1w/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/IVby2exqn1w/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/IVby2exqn1w/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "MRMURK4G3",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"nlUZBA6NbTS7q9G8D1GljyfTIWI/xq6mXfyCDDr8-C03ueN-4GhGP7U\"",
"id": {
"kind": "youtube#video",
"videoId": "QcD6RLYc34w"
},
"snippet": {
"publishedAt": "2017-12-01T21:26:39.000Z",
"channelId": "UCzfu8Y5CsN7OCLJhZy_fH6w",
"title": "How To: Make A Qooh.Me Spammer! (C#)",
"description": "In this video i show you how to make a simple spammer for anonymous question websites. Find this video helpful in any way? Be sure to drop a like & comment ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/QcD6RLYc34w/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/QcD6RLYc34w/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/QcD6RLYc34w/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "MRMURK4G3",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"nlUZBA6NbTS7q9G8D1GljyfTIWI/J8WfMLAVh58rILoataElddP5Q_o\"",
"id": {
"kind": "youtube#video",
"videoId": "iAwevpZK9Ug"
},
"snippet": {
"publishedAt": "2017-11-19T19:21:23.000Z",
"channelId": "UCzfu8Y5CsN7OCLJhZy_fH6w",
"title": "Proxies24",
"description": "Advertisement video, please click off if you're not interested! This is a short video to get a new site im a part of get started. Please let me know your thoughts on it.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/iAwevpZK9Ug/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/iAwevpZK9Ug/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/iAwevpZK9Ug/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "MRMURK4G3",
"liveBroadcastContent": "none"
}
}
YouTube Data API request returns the JSON data that includes the information of the video (title, description, thumbnails, publish date, etc.). You need to specify the API key ($API_key), YouTube Channel ID ($channelID).
//Get videos from channel by YouTube Data API
$API_key = 'Insert_Your_API_Key';
$channelID = 'Insert_Channel_ID';
$maxResults = 10;
$videoList = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId='.$channelID.'&maxResults='.$maxResults.'&key='.$API_key.''));
Youtube Video List using PHP Loop through the $videoList->items to list the videos from a YouTube channel.
foreach($videoList->items as $item){
//Embed video
if(isset($item->id->videoId)){
echo '<div class="youtube-video">
<iframe width="280" height="150" src="https://www.youtube.com/embed/'.$item->id->videoId.'" frameborder="0" allowfullscreen></iframe>
<h2>'. $item->snippet->title .'</h2>
</div>';
}
}
In the YouTube video list, Video ID and Title are used, but you can show the other information as per your requirement. The following information is provided by the API.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments