PHP code example of khaleejinfotech / youtube-data-api-laravel

1. Go to this page and download the library: Download khaleejinfotech/youtube-data-api-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

khaleejinfotech / youtube-data-api-laravel example snippets




return [
    'key' => env('YOUTUBE_DATA_API')
];




namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Khaleejinfotech\YoutubeDataApi\YoutubeDataApi;

class TestController extends Controller
{
	//Create a fetch function for display
    public function fetch(){

        // Try query the video metadata by video Id
        $youtubeDataApi = new YoutubeDataApi();
        $youtubeDataApi->setVideoID("cT1Df9lpYw8");
        $videoData= $youtubeDataApi->fetch();
		
        echo 'VideoID           : ' . $videoData->videoId . "<br>";
        echo 'Title             : ' . $videoData->title . "<br>";
        echo 'Description       : ' . $videoData->description . "<br>";
        echo 'Channel Title     : ' . $videoData->channelTitle . "<br>";		
        echo 'Published At      : ' . $videoData->publishedAt ;
        
        $thumbnails = $videoData->thumbnails; // Returns array of different thumbnail sizes. 
        
        $defaultImageUrl = $thumbnails->default->url;
        $defaultImageWidth = $thumbnails->default->width;
        $defaultImageHeight = $thumbnails->default->height;
        
        $mediumImageUrl = $thumbnails->medium->url;
        $mediumImageWidth = $thumbnails->medium->width;
        $mediumImageHeight = $thumbnails->medium->height;
        
        $highImageUrl = $thumbnails->high->url;
        $highImageWidth = $thumbnails->high->width;
        $highImageHeight = $thumbnails->high->height;
        
    }
}

php artisan vendor:publish --tag="youtube_data_api"

php artisan make:controller TestController