Fetch data from youtube video list

Dominik Weber

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"
   }
  }
MimoudiX

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.

  • YouTube Video ID – $item->id->videoId
  • YouTube Video Publish Date – $item->snippet->publishedAt
  • YouTube Channel ID – $item->snippet->channelId
  • YouTube Video Title – $item->snippet->title
  • YouTube Video Description – $item->snippet->description
  • YouTube Video Thumbnail URL (default size) – $item->snippet->thumbnails->default->url
  • YouTube Video Thumbnail URL (medium size) – $item->snippet->thumbnails->medium->url
  • YouTube Video Thumbnail URL (large size) – $item->snippet->thumbnails->high->url
  • YouTube Channel Title – $item->snippet->channelTitle

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Return same YouTube video while fetch data

Fetching YouTube transcript data from a list of video_ids

Fetch YouTube Video Id from youtube URL in zend framework

Fetching Video data from YouTube's video list API bringing wrong data

Fetch title and description from a YouTube video URL in Andorid

How to get the data of a video from youtube in javascript

Get video information from a list of playlist with youtube-dl

Play first youtube embedded video from a list of link using jQuery

how to get contentDetails part from youtube video list

Fetch JSON list data from api

Fetch Data from recordset and store it in list

Cannot fetch all youtube video urls of a channel

Youtube Data API V3 - Error fetching video with google.youtube.videos.list()

Fetching YouTube video list in Titanium

Youtube Data API - How to get video comments from multiple video id

Video Upload to youtube from app

Autostart a youtube video from Javascript

screengrab from a youtube video in javascript

Embed Youtube video from URL

Removing video from embed youtube video

How to get video tags from youtube video?

Fetch list of videos from Youtube channels using Youtube API v3 (without the annoying authentication pop-up)

Fetch data from sqlite3 and save in list

How to fetch data inside list from api response in flutter?

How to fetch "ME" (Owner Profile) profile data from contact list?

How do i fetch data as a List from json using Retrofit

Fetch Data from web service and store it in array list

Fetch video details on Youtube using API v3 in PHP

Vanilla JS nested fetch with youtube data API