Integrate youtube upload video in Laravel
Posted By : Vishal Yadav | 13-Apr-2020
In this tutorial we will talk about uploading videos in single youtube channel(account) not multiple.
Pull the following package from github via composer
composer require dawson/youtube
Register in the service provider in `config/app.php`
'providers' => [ ... Dawson\Youtube\YoutubeServiceProvider::class, ],
Add alias for same provider with in the same file.
'aliases' => [ ... 'Youtube' => Dawson\Youtube\Facades\Youtube::class, ],
Publish youtube.php config file and migrate.
php artisan vendor:publish --provider="Dawson\Youtube\YoutubeServiceProvider"
For migration use the artisan migrate command to generate table to store youtube access tokens
php artisan migrate
To abtain the access make changes in config/youtube.php
change enabled to true to access the youtube auth url. By default auth url is disabled because of security issue.
Visit to your google app and copy the client_id and secreat code.
Put same on your .env file as
Add http://YOUR_SITE_URL/youtube/callback in your app auth urls.
Visit to page http://YOUR_SITE_URL/youtube/auth to link the youtube channel to your site.
Hurry, thats it. Create a controller in Laravel and use below code to upload video to youtube channel.
$fullPathToVideo = storage_path('app/public/video.mp4');
$video = Youtube::upload($fullPathToVideo, [ 'title' => 'My Video', 'description' => 'Video description here.', 'tags' => ['some', 'tags', 'here'], 'category_id' => 7 ]); return $video->getVideoId();
In order to delete the video use