PHP Classes

PHP YouTube API Get Video Info: Get details and manage videos using YouTube API v3

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 128 All time: 9,387 This week: 33Up
Version License PHP version Categories
youtube-client 1.0.0BSD License5PHP 5, Web services, Video
Description 

Author

This class can access and get details and manage videos using YouTube API v3.

It can send HTTP requests to the YouTube API v3 Web server to perform operations with videos hosted in YouTube.

Currently it can retrieve the details of a list of videos that match given parameters.

Picture of Manuel Lemos
  Performance   Level  
Name: Manuel Lemos <contact>
Classes: 45 packages by
Country: Portugal Portugal

Example

<?php
/*
 * example_get_video.php
 *
 * @(#) $Id: example_get_video.php,v 1.1 2016/10/08 08:37:01 mlemos Exp $
 *
 */

   
require('youtube_client.php');
   
   
$youtube = new youtube_client_class;
   
$youtube->key = ''; $application_line = __LINE__;
   
    if(
strlen($youtube->key) === 0)
    {
        die(
'Please go to Google Developer Console, get a key for the '.
           
'YouTube API and set it in the line '.$application_line);
    }

   
$parameters = array(
       
'id'=>'3Xw3617p06M'
   
);
   
$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>


  Files folder image Files (2)  
File Role Description
Accessible without login Plain text file example_get_video.php Example YouTube get video example
Plain text file youtube_client.php Class YouTube client class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Reuses Unique User Downloads Download Rankings  
 100%1
Total:128
This week:0
All time:9,387
This week:33Up